@Override public Line2d initialValue() { return new Line2d(); } };
public void getPointAndNormalizedVector(Point2d pointToPack, Vector2d normalizedVectorToPack) { getPoint(pointToPack); getNormalizedVector(normalizedVectorToPack); }
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); }
@Override public Line2d applyTransformCopy(RigidBodyTransform transform) { Line2d copy = new Line2d(this); copy.applyTransform(transform); return copy; }
@Override public Line2d applyTransformAndProjectToXYPlaneCopy(RigidBodyTransform transform) { Line2d copy = new Line2d(this); copy.applyTransformAndProjectToXYPlane(transform); return copy; }
@Override public void setIncludingFrame(FrameLine2d otherFrameLine2d) { this.referenceFrame = otherFrameLine2d.referenceFrame; this.line.set(otherFrameLine2d.line); }
public void paint(Graphics graphics) { Color originalGraphicsColor = graphics.getColor(); graphics.setColor(Color.red); Graphics2D g2d = (Graphics2D) graphics; Stroke originalStroke = g2d.getStroke(); g2d.setStroke(new BasicStroke(lineThickness)); Line2d xMin = new Line2d(new Point2d(0, 0), new Vector2d(1.0, 0.0)); Line2d xMax = new Line2d(new Point2d(0, imageHeight), new Vector2d(1.0, 0.0)); for (Line2d line : lines) { Point2d p1 = line.intersectionWith(xMin); Point2d p2 = line.intersectionWith(xMax); graphics.drawLine((int) p1.getX(), (int)p1.getY(), (int)p2.getX(), (int) p2.getY()); } graphics.setColor(originalGraphicsColor); g2d.setStroke(originalStroke); } }
edgeOnQ.set(vertexQ, nextVertexQ); edgeOnQ.perpendicularVector(vectorPerpendicularToEdgeOnQ); LinePerpendicularToEdgeOnQ.set(vertexQ, vectorPerpendicularToEdgeOnQ); LinePerpendicularToEdgeOnQ.getPointGivenParameter(distance, referencePoint); edgeOnQ.getNormalizedVector(normalizedVector); newEdge.set(referencePoint, normalizedVector); rays.add(newEdge);
if (line.isPointOnLine(vertex)) if (line.isPointOnLine(vertex0) && line.isPointOnLine(vertex1)) double edgeVectorX = edgeEnd.x - edgeStart.x; double edgeVectorY = edgeEnd.y - edgeStart.y; Point2d lineStart = line.getPoint(); Vector2d lineDirection = line.getNormalizedVector(); double lambda = getIntersectionLambda(edgeStart.x, edgeStart.y, edgeVectorX, edgeVectorY, lineStart.x, lineStart.y, lineDirection.x, lineDirection.y);
private ArrayList<Point2d> getAllIntersections() { ArrayList<Point2d> intersections = new ArrayList<Point2d>(); ArrayList<Line2d> linesCopy = new ArrayList<Line2d>(lines); for (Line2d line : lines) { int count = 0; linesCopy.remove(line); for (Line2d line2d : linesCopy) { count++; Point2d intersection = line.intersectionWith(line2d); if (intersection != null) { intersections.add(intersection); } } } return intersections; } }
public Line2d perpendicularLineThroughPoint(Point2d point) { return new Line2d(point, perpendicularVector()); }
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; }
if (nextContactFramePosition != null) Line2d line2d = new Line2d(projectionSegment.getFirstEndpointCopy(), projectionSegment.getSecondEndpointCopy()); Point2d nextPoint2d = new Point2d(nextContactFramePosition.getX(), nextContactFramePosition.getY()); line2d.orthogonalProjectionCopy(nextPoint2d); xSNext = projectionSegment.percentageAlongLineSegment(nextPoint2d) * projectionSegment.length();
public void getPoint2d(Point2d origin) { line.getPoint(origin); }
if (line.getSlope() < leftEdgeOfRoad.getSlope()) if (line.getSlope() > rightEdgeOfRoad.getSlope()) double leftX = leftEdgeOfRoad.intersectionWith(axis).getX(); double rightX = rightEdgeOfRoad.intersectionWith(axis).getX(); double range = rightX - leftX; double midPoint = leftX + (range / 2.0);
if ((previousPointToCheck != null) && (ray.isPointOnLeftSideOfLine(previousPointToCheck))) if (intersection == null) throw new RuntimeException("intersection == null!"); boolean foundIntersection = ray.intersectionWith(previousRayToCheck, intersection); if (evenMorePreviousRayToCheck.isPointOnLeftSideOfLine(intersection)) foundIntersection = ray.intersectionWith(evenMorePreviousRayToCheck, intersection); if (!foundIntersection)
public boolean areLinesPerpendicular(Line2d line) { // Dot product of two vectors is zero if the vectors are perpendicular return normalizedVector.dot(line.getNormalizedVector()) < 1e-7; }
@Override public FramePoint2d orthogonalProjectionCopy(FramePoint2d point) { checkReferenceFrameMatch(point); Point2d projected = line.orthogonalProjectionCopy(point.getPoint()); return new FramePoint2d(point.getReferenceFrame(), projected); }
public void setLine(Line2d line) { line.getTwoPointsOnLine(point1, point2); }