@Override public double heightAt(double x, double y, double z) { if (planarRegion.isPointInsideByProjectionOntoXYPlane(x, y)) { return planarRegion.getPlaneZGivenXY(x, y); } else { return 0.0; } }
/** * Find all the planar regions that contain the given point. * The algorithm is equivalent to projecting all the regions onto the XY-plane and then finding the regions containing the point. * @param x the query x-coordinate. * @param y the query y-coordinate. * @return the list of planar regions containing the query. Returns null when no region contains the query. */ public List<PlanarRegion> findPlanarRegionsContainingPointByProjectionOntoXYPlane(double x, double y) { List<PlanarRegion> containers = null; for (int i = 0; i < regions.size(); i++) { PlanarRegion candidateRegion = regions.get(i); if (candidateRegion.isPointInsideByProjectionOntoXYPlane(x, y)) { if (containers == null) containers = new ArrayList<>(); containers.add(candidateRegion); } } return containers; }
/** * Find all the planar regions that contain the given point. The algorithm is equivalent to * projecting all the regions onto the XY-plane and then finding the regions containing the * point. * * @param x the query x-coordinate. * @param y the query y-coordinate. * @return the list of planar regions containing the query. Returns null when no region contains * the query. */ public List<PlanarRegion> findPlanarRegionsContainingPointByProjectionOntoXYPlane(double x, double y) { List<PlanarRegion> containers = null; for (int i = 0; i < regions.size(); i++) { PlanarRegion candidateRegion = regions.get(i); if (candidateRegion.isPointInsideByProjectionOntoXYPlane(x, y)) { if (containers == null) containers = new ArrayList<>(); containers.add(candidateRegion); } } return containers; }
/** * Computes if the point is in the region projected onto the world xy-plane. * * @param point2d query coordinates. * @return true if the point is inside this region, false otherwise. */ public boolean isPointInsideByProjectionOntoXYPlane(Point2DReadOnly point2d) { return isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY()); }
/** * Computes if the point is in the region projected onto the world xy-plane. Note that the * z-coordinate of the query is ignored. * * @param point3d query coordinates. * @return true if the point is inside this region, false otherwise. */ public boolean isPointInsideByProjectionOntoXYPlane(Point3DReadOnly point3d) { return isPointInsideByProjectionOntoXYPlane(point3d.getX(), point3d.getY()); }
/** * Computes if the point is in the region projected onto the world xy-plane. * Note that the z-coordinate of the query is ignored. * @param point3d query coordinates. * @return true if the point is inside this region, false otherwise. */ public boolean isPointInsideByProjectionOntoXYPlane(Point3d point3d) { return isPointInsideByProjectionOntoXYPlane(point3d.getX(), point3d.getY()); }
/** * Computes if the point is in the region projected onto the world xy-plane. * @param point2d query coordinates. * @return true if the point is inside this region, false otherwise. */ public boolean isPointInsideByProjectionOntoXYPlane(Point2d point2d) { return isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY()); }
@Override public double heightAndNormalAt(double x, double y, double z, Vector3D normalToPack) { if (planarRegion.isPointInsideByProjectionOntoXYPlane(x, y)) { if (normalToPack != null) { planarRegion.getNormal(normalToPack); } return planarRegion.getPlaneZGivenXY(x, y); } else { normalToPack.set(0.0, 0.0, 1.0); return 0.0; } }
@ContinuousIntegrationTest(estimatedDuration = 5.0) @Test(timeout = 30000) public void testHeightAt() throws Exception { Random random = new Random(1776L); for (int i = 0; i < 100000; i++) { PlanarRegion planarRegion = PlanarRegion.generatePlanarRegionFromRandomPolygonsWithRandomTransform(random, random.nextInt(10), RandomNumbers.nextDouble(random, 0.0, 30.0), random.nextInt(10)); BoundingBox3D boundingBox3dInWorld = planarRegion.getBoundingBox3dInWorld(); double randomXCoord = RandomNumbers.nextDouble(random, boundingBox3dInWorld.getMinX() - 10.0, boundingBox3dInWorld.getMaxX() + 10.0); double randomYCoord = RandomNumbers.nextDouble(random, boundingBox3dInWorld.getMinY() - 10.0, boundingBox3dInWorld.getMaxY() + 10.0); double randomZCoord = RandomNumbers.nextDouble(random, boundingBox3dInWorld.getMinZ() - 10.0, boundingBox3dInWorld.getMaxZ() + 10.0); PlanarRegionTerrainObject terrainObject = new PlanarRegionTerrainObject(planarRegion, DEFAULT_ALLOWABLE_PENETRATION_THICKNESS); double planarRegionZAtXY = planarRegion.getPlaneZGivenXY(randomXCoord, randomYCoord); if (planarRegion.isPointInsideByProjectionOntoXYPlane(randomXCoord, randomYCoord)) { assertEquals(planarRegionZAtXY, terrainObject.heightAt(randomXCoord, randomYCoord, randomZCoord), 1e-10); } else { assertNotEquals(planarRegionZAtXY, terrainObject.heightAt(randomXCoord, randomYCoord, randomZCoord), 1e-10); } } }
planarRegion.getNormal(planarRegionNormalToPack); if (planarRegion.isPointInsideByProjectionOntoXYPlane(randomXCoord, randomYCoord))
if (shouldGeneratePointGuaranteedOnPlane && planarRegion.isPointInsideByProjectionOntoXYPlane(randomXCoord, randomYCoord))
assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(0.0, 0.0)); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(2.0, 0.0)); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(0.0, 2.0)); assertFalse(planarRegion.isPointInsideByProjectionOntoXYPlane(2.0, 2.0)); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.set(2.0, 0.0); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.set(0.0, 2.0); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.set(2.0, 2.0); assertFalse(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d)); point3d.set(2.0, 0.0, Double.POSITIVE_INFINITY); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d)); point3d.set(0.0, 2.0, Double.POSITIVE_INFINITY); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d)); point3d.set(2.0, 2.0, Double.POSITIVE_INFINITY); assertFalse(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d));
assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY())); point2d.setIncludingFrame(localFrame, 2.0, 0.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY())); point2d.setIncludingFrame(localFrame, 0.0, 2.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY())); point2d.setIncludingFrame(localFrame, 2.0, 2.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertFalse(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d.getX(), point2d.getY())); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.setIncludingFrame(localFrame, 2.0, 0.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.setIncludingFrame(localFrame, 0.0, 2.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point2d.setIncludingFrame(localFrame, 2.0, 2.0); point2d.changeFrameAndProjectToXYPlane(worldFrame); assertFalse(planarRegion.isPointInsideByProjectionOntoXYPlane(point2d)); point3d.changeFrame(worldFrame); point3d.setZ(Double.POSITIVE_INFINITY); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d)); point3d.setIncludingFrame(localFrame, 2.0, 0.0, 0.0); point3d.changeFrame(worldFrame); point3d.setZ(Double.POSITIVE_INFINITY); assertTrue(planarRegion.isPointInsideByProjectionOntoXYPlane(point3d));