Skip to content
Snippets Groups Projects
Commit 3993e758 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Added a speed-up for elliptical Fov offset computation.

parent 8eab5e81
Branches
Tags
No related merge requests found
...@@ -243,7 +243,21 @@ public class EllipticalFieldOfView extends SmoothFieldOfView { ...@@ -243,7 +243,21 @@ public class EllipticalFieldOfView extends SmoothFieldOfView {
public double offsetFromBoundary(final Vector3D lineOfSight, final double angularRadius, public double offsetFromBoundary(final Vector3D lineOfSight, final double angularRadius,
final VisibilityTrigger trigger) { final VisibilityTrigger trigger) {
// find closest point on ellipse final double margin = getMargin();
final double correctedRadius = trigger.radiusCorrection(angularRadius);
final double deadBand = margin + angularRadius;
// for faster computation, we start using only the surrounding cap, to filter out
// far away points (which correspond to most of the points if the Field Of View is small)
final double crudeDistance = Vector3D.angle(getZ(), lineOfSight) - a;
if (crudeDistance > deadBand + 0.01) {
// we know we are strictly outside of the zone,
// use the crude distance to compute the (positive) return value
return crudeDistance + correctedRadius - margin;
}
// we are close, we need to compute carefully the exact offset;
// we project the point to the closest zone boundary
final double d1 = Vector3D.angle(lineOfSight, focus1); final double d1 = Vector3D.angle(lineOfSight, focus1);
final double d2 = Vector3D.angle(lineOfSight, focus2); final double d2 = Vector3D.angle(lineOfSight, focus2);
final Vector3D closest = projectToBoundary(lineOfSight, d1, d2); final Vector3D closest = projectToBoundary(lineOfSight, d1, d2);
...@@ -252,7 +266,7 @@ public class EllipticalFieldOfView extends SmoothFieldOfView { ...@@ -252,7 +266,7 @@ public class EllipticalFieldOfView extends SmoothFieldOfView {
final double rawOffset = FastMath.copySign(Vector3D.angle(lineOfSight, closest), final double rawOffset = FastMath.copySign(Vector3D.angle(lineOfSight, closest),
d1 + d2 - 2 * a); d1 + d2 - 2 * a);
return rawOffset + trigger.radiusCorrection(angularRadius) - getMargin(); return rawOffset + correctedRadius - getMargin();
} }
......
...@@ -261,7 +261,7 @@ public class EllipticalFieldOfViewTest extends AbstractSmoothFieldOfViewTest { ...@@ -261,7 +261,7 @@ public class EllipticalFieldOfViewTest extends AbstractSmoothFieldOfViewTest {
doTestPointsNearBoundary(new EllipticalFieldOfView(Vector3D.PLUS_I, Vector3D.PLUS_J, doTestPointsNearBoundary(new EllipticalFieldOfView(Vector3D.PLUS_I, Vector3D.PLUS_J,
FastMath.toRadians(10.0), FastMath.toRadians(40.0), FastMath.toRadians(10.0), FastMath.toRadians(40.0),
0.0), 0.0),
0.1, 0.0794625, 0.1, 1.0e-7); 0.1, 0.0101573, 0.1, 1.0e-7);
} }
@Test @Test
...@@ -356,8 +356,18 @@ public class EllipticalFieldOfViewTest extends AbstractSmoothFieldOfViewTest { ...@@ -356,8 +356,18 @@ public class EllipticalFieldOfViewTest extends AbstractSmoothFieldOfViewTest {
minDist = FastMath.min(minDist, Vector3D.angle(los, fov.directionAt(eta))); minDist = FastMath.min(minDist, Vector3D.angle(los, fov.directionAt(eta)));
} }
minDist = FastMath.copySign(minDist, d1 + d2 - 2 * a); minDist = FastMath.copySign(minDist, d1 + d2 - 2 * a);
double offset = fov.offsetFromBoundary(los, 0.0, VisibilityTrigger.VISIBLE_ONLY_WHEN_FULLY_IN_FOV);
Assert.assertEquals(minDist, offset, 3.0e-7); // here, we intentionally use an impossibly large radius to ensure we don't use the speed-up
// and compute offset as an exact angle
double hugeRadius = FastMath.PI;
double realOffset = fov.offsetFromBoundary(los, hugeRadius, VisibilityTrigger.VISIBLE_ONLY_WHEN_FULLY_IN_FOV);
Assert.assertEquals(minDist + hugeRadius, realOffset, 3.0e-7);
// here, we intentionally use a zero radius, so we may use the speed-up
// and may underestimate the offset
double approximateOffset = fov.offsetFromBoundary(los, 0.0, VisibilityTrigger.VISIBLE_ONLY_WHEN_FULLY_IN_FOV);
Assert.assertTrue(approximateOffset < minDist + 3.0e-7);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment