@@ -238,7 +238,7 @@ def plot_sigmas(sigmas, x, cov):
238
238
pts = sigmas .sigma_points (x = x , P = cov )
239
239
plt .scatter (pts [:, 0 ], pts [:, 1 ], s = sigmas .Wm * 1000 )
240
240
plt .axis ('equal' )
241
-
241
+
242
242
243
243
def plot_sigma_points ():
244
244
x = np .array ([0 , 0 ])
@@ -383,20 +383,38 @@ def plot_scatter_moving_target():
383
383
384
384
def _isct (pa , pb , alpha , beta ):
385
385
""" 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
387
387
point pb.
388
388
"""
389
389
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
396
417
397
- AP = (sin (b ) / sin (p )) * AB
398
- x = cos (alpha ) * AP + pa [0 ]
399
- y = sin (alpha ) * AP + pa [1 ]
400
418
return x , y
401
419
402
420
@@ -415,7 +433,7 @@ def _plot_iscts(pos, sa, sb, N=4):
415
433
a_a = actual_angle_a + randn () * math .radians (1 )
416
434
a_b = actual_angle_b + randn () * math .radians (1 )
417
435
418
- x ,y = _isct (sa , sb , a_a , a_b )
436
+ x , y = _isct (sa , sb , a_a , a_b )
419
437
xs .append (x )
420
438
ys .append (y )
421
439
0 commit comments