public double distanceSquared(Point2d point) { double distance = distance(point); return distance * distance; }
@Override public double distance(FrameLineSegment2d lineSegment) { checkReferenceFrameMatch(lineSegment); return this.line.distance(lineSegment.lineSegment); }
@Override public double distance(FrameConvexPolygon2d convexPolygon) { checkReferenceFrameMatch(convexPolygon); return this.line.distance(convexPolygon.convexPolygon); }
@Override public double distance(FrameLine2d secondLine) { checkReferenceFrameMatch(secondLine); return this.line.distance(secondLine.line); }
@Override public double distance(FramePoint2d point) { checkReferenceFrameMatch(point); return this.line.distance(point.getPoint()); }
/** * Returns the index of the closest vertex of the polygon to the given line. If there * are multiple closest vertices (line parallel to an edge) this will return the smaller * index. */ public static int getClosestVertexIndex(Line2d line, ConvexPolygon2d polygon) { double minDistance = Double.POSITIVE_INFINITY; int index = -1; for (int i = 0; i < polygon.getNumberOfVertices(); i++) { Point2d vertex = polygon.getVertex(i); double distance = line.distance(vertex); if (distance < minDistance) { index = i; minDistance = distance; } } return index; }
private int findWorstMaxViolatorIndex(Point2d startPoint, Point2d endPoint, int startIndex, int endIndex) { tempLine.set(startPoint, endPoint); int returnIndex = -1; double worstViolation = Double.NEGATIVE_INFINITY; for (int i = startIndex; i <= endIndex; i++) { Point2d[] minMaxPoint = getMinMaxPoint(i); Point2d maxPoint = minMaxPoint[1]; if (tempLine.isPointOnRightSideOfLine(maxPoint)) { double distance = tempLine.distance(maxPoint); if (distance > worstViolation) { worstViolation = distance; returnIndex = i; } } } return returnIndex; }
private int findWorstMinViolatorIndex(Point2d startPoint, Point2d endPoint, int startIndex, int endIndex) { tempLine.set(startPoint, endPoint); int returnIndex = -1; double worstViolation = Double.NEGATIVE_INFINITY; for (int i = startIndex; i <= endIndex; i++) { Point2d[] minMaxPoint = getMinMaxPoint(i); Point2d minPoint = minMaxPoint[0]; if (tempLine.isPointOnLeftSideOfLine(minPoint)) { double distance = tempLine.distance(minPoint); if (distance > worstViolation) { worstViolation = distance; returnIndex = i; } } } return returnIndex; }
public Line2d interiorBisector(Line2d secondLine) { Point2d pointOnLine = intersectionWith(secondLine); if (pointOnLine == null) { double distanceBetweenLines = secondLine.distance(point); double epsilon = 1E-7; boolean sameLines = distanceBetweenLines < epsilon; if (sameLines) { return new Line2d(this); } else { return null; } } Vector2d directionVector = new Vector2d(normalizedVector); directionVector.add(secondLine.normalizedVector); return new Line2d(pointOnLine, directionVector); }