public FramePoint2d getClosestVertexCopy(FrameLine2d line) { line.checkReferenceFrameMatch(referenceFrame); Point2d closestVertexCopy = ConvexPolygon2dCalculator.getClosestVertexCopy(line.line, convexPolygon); if (closestVertexCopy == null) throw new RuntimeException("Closest vertex could not be found! Has at least one vertex: " + convexPolygon.hasAtLeastOneVertex()); return new FramePoint2d(referenceFrame, closestVertexCopy); }
if (!polygon.hasAtLeastOneVertex()) return;
if (!polygon.hasAtLeastOneVertex()) return false;
/** * Packs the point on the polygon that is closest to the given ray. If the ray is parallel to the * closest edge this will return the point on that edge closest to the ray origin. If the ray * intersects the polygon the result of this method will be wrong. If unsure check first using the * intersectionWithRay method. */ public static boolean getClosestPointToRay(Line2d ray, Point2d pointToPack, ConvexPolygon2d polygon) { if (!polygon.hasAtLeastOneVertex()) return false; Point2d rayStart = ray.getPoint(); Vector2d rayDirection = ray.getNormalizedVector(); int closestVertexIndex = getClosestVertexIndex(ray, polygon); Point2d closestVertexToLine = polygon.getVertex(closestVertexIndex); // validate the closest vertex is in front of the ray: boolean vertexValid = isPointInFrontOfRay(rayStart, rayDirection, closestVertexToLine); // check edges adjacent to the closest vertex to determine if they are parallel to the ray: boolean edge1Parallel = isEdgeParallel(closestVertexIndex, rayDirection, polygon); boolean edge2Parallel = isEdgeParallel(polygon.getNextVertexIndex(closestVertexIndex), rayDirection, polygon); boolean rayParallelToEdge = edge1Parallel || edge2Parallel; if (vertexValid && !rayParallelToEdge) pointToPack.set(closestVertexToLine); else { pointToPack.set(rayStart); orthogonalProjection(pointToPack, polygon); } return true; }
if (polygonP.hasExactlyOneVertex() && polygonQ.hasAtLeastOneVertex())
public static ConvexPolygon2d shrinkInto(ConvexPolygon2d polygonP, Point2d referencePointInP, ConvexPolygon2d polygonQ) if (polygonQ.hasAtLeastOneVertex() && !polygonQ.hasAtLeastThreeVertices())
maxXminY_index = 0; if (hasAtLeastOneVertex())