private void initSidePlanes() { Vector2D normal2d = new Vector2D(); for (int i = 0; i < convexPolygon.getNumberOfVertices(); i++) { ConvexPolygon2dCalculator.getEdgeNormal(i, normal2d, convexPolygon); Vector3D normal = new Vector3D(normal2d.getX(), normal2d.getY(), 0.0); int secondIndex = (i + 1 < convexPolygon.getNumberOfVertices()) ? i + 1 : 0; int[] indices = {i, secondIndex}; Point3D centerPoint = new Point3D(); Point3D checkingPoint = new Point3D(); for (int j : indices) { Point2DReadOnly vertex = convexPolygon.getVertex(j); checkingPoint.set(vertex.getX(), vertex.getY(), boundingBox.getMinZ()); checkingPoint.scale(0.25); centerPoint.add(checkingPoint); checkingPoint.set(vertex.getX(), vertex.getY(), heightAt(vertex.getX(), vertex.getY(), 0.0)); checkingPoint.scale(0.25); centerPoint.add(checkingPoint); } Plane3D sidePlane = new Plane3D(centerPoint, normal); sidePlanes.add(sidePlane); } }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testGetEdgeNormal() { ConvexPolygon2D polygon = new ConvexPolygon2D(); polygon.addVertex(new Point2D(-1.0, 0.0)); polygon.addVertex(new Point2D(0.0, 1.0)); polygon.addVertex(new Point2D(2.0, 0.0)); polygon.addVertex(new Point2D(1.0, -1.0)); polygon.update(); for (int i = 0; i < polygon.getNumberOfVertices(); i++) { Vector2D normal = new Vector2D(); ConvexPolygon2dCalculator.getEdgeNormal(i, normal, polygon); Vector2D expected = new Vector2D(); Point2DReadOnly edgeStart = polygon.getVertex(i); Point2DReadOnly edgeEnd = polygon.getNextVertex(i); Vector2D edgeVector = new Vector2D(); edgeVector.sub(edgeEnd, edgeStart); EuclidGeometryTools.perpendicularVector2D(edgeVector, expected); expected.normalize(); assertTrue("Expected normal Vector did not match computed one.", expected.epsilonEquals(normal, epsilon)); } }