/** * Returns the index in the middle of the range from firstIndex to secondIndex moving counter clockwise. * E.g. in a polygon with 6 vertices given indices 0 and 2 (in this order) the method will return the * middle of the range [0 5 4 3 2]: 4 */ public static int getMiddleIndexCounterClockwise(int firstIndex, int secondIndex, ConvexPolygon2d polygon) { int numberOfVertices = polygon.getNumberOfVertices(); if (secondIndex >= firstIndex) return (secondIndex + (firstIndex + numberOfVertices - secondIndex + 1) / 2) % numberOfVertices; else return (secondIndex + firstIndex + 1) / 2; }
public int getNumberOfVertices() { return convexPolygon.getNumberOfVertices(); }
public void setPoints(ConvexPolygon2d polygon) { this.points.clear(); for (int i = 0; i < polygon.getNumberOfVertices(); i++) this.points.add(polygon.getVertex(i)); }
public void setPoints(ConvexPolygon2d polygon) { this.points.clear(); for (int i = 0; i < polygon.getNumberOfVertices(); i++) this.points.add(polygon.getVertex(i)); }
@Override public boolean epsilonEquals(ConvexPolygon2d convexPolygon, double threshold) { checkIfUpToDate(); if (getNumberOfVertices() != convexPolygon.getNumberOfVertices()) return false; for (int i = 0; i < convexPolygon.getNumberOfVertices(); i++) { if (!convexPolygon.getVertex(i).epsilonEquals(getVertex(i), threshold)) return false; } return true; }
public static MeshDataHolder ExtrudedPolygon(ConvexPolygon2d convexPolygon2d, double extrusionHeight) { Point2d[] points = new Point2d[convexPolygon2d.getNumberOfVertices()]; for (int i = 0; i < convexPolygon2d.getNumberOfVertices(); i++) { points[i] = new Point2d(convexPolygon2d.getVertex(i)); } return ExtrudedPolygon(points, extrusionHeight); }
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; }
/** * 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); } }
/** * 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)); }
public void drawPolygonFilled(PlotterReferenceFrame frame, ConvexPolygon2d convexPolygon2d) { if (setupForDrawPolygon(frame, convexPolygon2d)) drawPolygonFilled(tempPoints[0], tempPoints[1], convexPolygon2d.getNumberOfVertices()); }
public void drawPolygon(PlotterReferenceFrame frame, ConvexPolygon2d convexPolygon2d) { setupForDrawPolygon(frame, convexPolygon2d); drawPolygon(tempPoints[0], tempPoints[1], convexPolygon2d.getNumberOfVertices()); }
public void drawPolygon(PlotterReferenceFrame frame, ConvexPolygon2d convexPolygon2d) { if (setupForDrawPolygon(frame, convexPolygon2d)) drawPolygon(tempPoints[0], tempPoints[1], convexPolygon2d.getNumberOfVertices()); }
public void drawPolygonFilled(PlotterReferenceFrame frame, ConvexPolygon2d convexPolygon2d) { setupForDrawPolygon(frame, convexPolygon2d); drawPolygonFilled(tempPoints[0], tempPoints[1], convexPolygon2d.getNumberOfVertices()); }
/** * Adds new vertices to this polygon from another convex polygon. * Note that this method recycles memory. * @param otherPolygon {@code FrameConvexPolygon2d} the other convex polygon that is used to add new vertices to this polygon. * @throws ReferenceFrameMismatchException */ public void addVertices(ConvexPolygon2d otherPolygon) { for (int i = 0; i < otherPolygon.getNumberOfVertices(); i++) { Point2d vertex = otherPolygon.getVertex(i); addVertex(vertex); } }
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 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(); }
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()); } }
public BasicFootstepMask(ConvexPolygon2d footstepShape, double maskBufferSize) { int numVertices = footstepShape.getNumberOfVertices(); Point2d vertex; for (int i = 0; i < numVertices; i++) { vertex = footstepShape.getVertex(i); footShapeWithBufferPolygon.addVertex(inflate(vertex.getX()), inflate(vertex.getY())); } footShapeWithBufferPolygon.update(); }
private void updateBoundingBox() { boundingBox3dInWorld.set(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN); for (int i = 0; i < this.getNumberOfConvexPolygons(); i++) { ConvexPolygon2d convexPolygon = this.getConvexPolygon(i); for (int j = 0; j < convexPolygon.getNumberOfVertices(); j++) { Point2d vertex = convexPolygon.getVertex(j); tempPointForConvexPolygonProjection.set(vertex.x, vertex.y, 0.0); fromLocalToWorldTransform.transform(tempPointForConvexPolygonProjection); this.boundingBox3dInWorld.updateToIncludePoint(tempPointForConvexPolygonProjection); } } }