public void setPoints(ConvexPolygon2d polygon) { this.points.clear(); for (int i = 0; i < polygon.getNumberOfVertices(); i++) this.points.add(polygon.getVertex(i)); }
/** Return the next vertex from a clockwise ordered list */ public Point2d getNextVertex(int index) { return getVertex(getNextVertexIndex(index)); }
/** Return the previous vertex from a clockwise ordered list */ public Point2d getPreviousVertex(int index) { return getVertex(getPreviousVertexIndex(index)); }
public static Point2d[] getLineOfSightVerticesCopy(Point2d observer, ConvexPolygon2d polygon) { int[] indices = getLineOfSightVertexIndicesCopy(observer, polygon); if (indices == null) return null; Point2d point1 = new Point2d(polygon.getVertex(indices[0])); Point2d point2 = new Point2d(polygon.getVertex(indices[1])); if (indices[0] == indices[1]) return new Point2d[] {point1}; return new Point2d[] {point1, point2}; }
protected void getPointsInClockwiseOrder(int startIndexInclusive, int endIndexInclusive, ArrayList<Point2d> pointList) { checkIfUpToDate(); int index = startIndexInclusive; while (true) { pointList.add(getVertex(index)); if (index == endIndexInclusive) break; index = getNextVertexIndex(index); } }
public ExtrudedPolygonGraphics3DInstruction addExtrudedPolygon(ConvexPolygon2d convexPolygon2d, double height, AppearanceDefinition appearance) { ArrayList<Point2d> polygonPoints = new ArrayList<Point2d>(); for (int i = 0; i < convexPolygon2d.getNumberOfVertices(); i++) { polygonPoints.add(convexPolygon2d.getVertex(i)); } ExtrudedPolygonGraphics3DInstruction extrudedPolygonInstruction = new ExtrudedPolygonGraphics3DInstruction(polygonPoints, height); extrudedPolygonInstruction.setAppearance(appearance); graphics3DInstructions.add(extrudedPolygonInstruction); return extrudedPolygonInstruction; }
/** * Adds new vertices to this polygon from another convex polygon. * Note that this method recycles memory. * @param otherPolygon {@code ConvexPolygon2d} the other convex polygon that is used to add new vertices to this polygon. */ public void addVertices(ConvexPolygon2d otherPolygon) { isUpToDate = false; for (int i = 0; i < otherPolygon.getNumberOfVertices(); i++) addVertex(otherPolygon.getVertex(i)); }
/** * Packs the closest vertex of the polygon to the given line. */ public static boolean getClosestVertex(Line2d line, ConvexPolygon2d polygon, Point2d pointToPack) { int index = getClosestVertexIndex(line, polygon); if (index < 0) return false; pointToPack.set(polygon.getVertex(index)); return true; }
public Point2d getMaxXMaxYPointCopy() { checkIfUpToDate(); return new Point2d(getVertex(maxXmaxY_index)); }
/** * Packs the closest vertex of the polygon to the given point */ public static boolean getClosestVertex(Point2d point, ConvexPolygon2d polygon, Point2d pointToPack) { int index = getClosestVertexIndex(point, polygon); if (index < 0) return false; pointToPack.set(polygon.getVertex(index)); return true; }
/** * Determines if the polygonToTest is inside the convex polygon. */ public static boolean isPolygonInside(ConvexPolygon2d polygonToTest, double epsilon, ConvexPolygon2d polygon) { for (int i = 0; i < polygonToTest.getNumberOfVertices(); i++) { if (!isPointInside(polygonToTest.getVertex(i), epsilon, polygon)) return false; } return true; }
/** * Translates the given polygon. */ public static void translatePolygon(Tuple2d translation, ConvexPolygon2d polygon) { for (int i = 0; i < polygon.getNumberOfVertices(); i++) { Point2d vertex = polygon.getVertex(i); vertex.add(translation); } }
public Point2d getMaxXMinYPointCopy() { checkIfUpToDate(); return new Point2d(getVertex(maxXminY_index)); }
protected void addVerticesInClockwiseOrderInPolygon(int startIndexInclusive, int endIndexInclusive, ConvexPolygon2d polygonToPack) { checkIfUpToDate(); int index = startIndexInclusive; while (true) { polygonToPack.addVertex(getVertex(index)); if (index == endIndexInclusive) break; index = getNextVertexIndex(index); } }
/** * Packs the closest edge to the given point. */ public static boolean getClosestEdge(Point2d point, ConvexPolygon2d polygon, LineSegment2d edgeToPack) { int edgeIndex = getClosestEdgeIndex(point, polygon); if (edgeIndex == -1) return false; edgeToPack.set(polygon.getVertex(edgeIndex), polygon.getNextVertex(edgeIndex)); return true; }
public void getFrameVertex(int vertexIndex, FrameTuple2d<?, ?> vertexToPack) { convexPolygon.checkIfUpToDate(); convexPolygon.checkNonEmpty(); convexPolygon.checkIndexInBoundaries(vertexIndex); vertexToPack.setIncludingFrame(referenceFrame, convexPolygon.getVertex(vertexIndex)); }
public void getFrameVertexXY(int vertexIndex, FramePoint vertexToPack) { convexPolygon.checkIfUpToDate(); convexPolygon.checkNonEmpty(); convexPolygon.checkIndexInBoundaries(vertexIndex); vertexToPack.setXYIncludingFrame(referenceFrame, convexPolygon.getVertex(vertexIndex)); }
private void updateConvexHull() { convexHull.clear(); for (int i = 0; i < this.getNumberOfConvexPolygons(); i++) { ConvexPolygon2d convexPolygon = this.getConvexPolygon(i); for (int j = 0; j < convexPolygon.getNumberOfVertices(); j++) convexHull.addVertex(convexPolygon.getVertex(j)); } convexHull.update(); }
public static MeshDataHolder Polygon(ConvexPolygon2d convexPolygon) { Point3f[] points = new Point3f[convexPolygon.getNumberOfVertices()]; for (int i = 0; i < convexPolygon.getNumberOfVertices(); i++) { Point2d vertex = convexPolygon.getVertex(i); points[i] = new Point3f((float) vertex.getX(), (float) vertex.getY(), 0.0f); } return Polygon(points); }
private void setupForDrawPolygon(PlotterReferenceFrame frame, ConvexPolygon2d convexPolygon2d) { for (int i = 0; i < convexPolygon2d.getNumberOfVertices(); i++) { pointBin[i].setIncludingFrame(frame, convexPolygon2d.getVertex(i)); pointBin[i].changeFrame(screenFrame); tempPoints[0][i] = pixelate(pointBin[i].getX()); tempPoints[1][i] = pixelate(pointBin[i].getY()); } }