@@ -238,7 +238,7 @@ def plot_sigmas(sigmas, x, cov):
238238 pts = sigmas .sigma_points (x = x , P = cov )
239239 plt .scatter (pts [:, 0 ], pts [:, 1 ], s = sigmas .Wm * 1000 )
240240 plt .axis ('equal' )
241-
241+
242242
243243def plot_sigma_points ():
244244 x = np .array ([0 , 0 ])
@@ -383,20 +383,38 @@ def plot_scatter_moving_target():
383383
384384def _isct (pa , pb , alpha , beta ):
385385 """ Returns the (x, y) intersections of points pa and pb
386- given the bearing ba for point pa and bearing bb for
386+ given the bearing alpha for point pa and bearing beta for
387387 point pb.
388388 """
389389
390- B = [pb [0 ] - pa [0 ], pb [1 ] - pa [1 ]]
391- AB = math .sqrt ((pa [0 ] - pb [0 ])** 2 + (pa [1 ] - pb [1 ])** 2 )
392- ab = atan2 (B [1 ], B [0 ])
393- a = alpha - ab
394- b = pi - beta - ab
395- p = pi - b - a
390+ ax , ay = pa
391+ cx , cy = pb
392+
393+ # bearing to angle
394+ alpha = 90 - alpha
395+ beta = 90 - beta
396+
397+ # compute second point, let hypot==1
398+ bx = cos (alpha ) + ax
399+ by = sin (alpha ) + ay
400+ dx = cos (beta ) + cx
401+ dy = sin (beta ) + cy
402+
403+ # Line AB represented as a1x + b1y = c1
404+ # Line CD represented as a2x + b2y = c2
405+
406+ a1 = by - ay
407+ b1 = ax - bx
408+ c1 = a1 * ax + b1 * ay
409+
410+ a2 = dy - cy
411+ b2 = cx - dx
412+ c2 = a2 * cx + b2 * cy
413+ det = a1 * b2 - a2 * b1
414+
415+ x = (b2 * c1 - b1 * c2 ) / det
416+ y = (a1 * c2 - a2 * c1 ) / det
396417
397- AP = (sin (b ) / sin (p )) * AB
398- x = cos (alpha ) * AP + pa [0 ]
399- y = sin (alpha ) * AP + pa [1 ]
400418 return x , y
401419
402420
@@ -415,7 +433,7 @@ def _plot_iscts(pos, sa, sb, N=4):
415433 a_a = actual_angle_a + randn () * math .radians (1 )
416434 a_b = actual_angle_b + randn () * math .radians (1 )
417435
418- x ,y = _isct (sa , sb , a_a , a_b )
436+ x , y = _isct (sa , sb , a_a , a_b )
419437 xs .append (x )
420438 ys .append (y )
421439
0 commit comments