/** * Compute the 2D equivalent of this line segment. * The 2D equivalent of each end point is computed as follows: * {@code endPoint2d = endPoint1d * direction2d + zero2d}. * @param zero2d position of the 2D equivalent of an endpoint equal to zero. * @param direction2d direction toward greater values of {@code endPoint1d}. * @return the 2D equivalent of this line segment. */ public LineSegment2d toLineSegment2d(Point2d zero2d, Vector2d direction2d) { LineSegment2d lineSegment2d = new LineSegment2d(); lineSegment2d.getFirstEndpoint().scaleAdd(endpoint1, direction2d, zero2d); lineSegment2d.getSecondEndpoint().scaleAdd(endpoint2, direction2d, zero2d); return lineSegment2d; }
public void drawLineSegment(PlotterReferenceFrame frame, LineSegment2d lineSegment) { PlotterPoint2d firstEndpoint = pointBin[0]; PlotterPoint2d secondEndpoint = pointBin[1]; firstEndpoint.setIncludingFrame(frame, lineSegment.getFirstEndpoint()); secondEndpoint.setIncludingFrame(frame, lineSegment.getSecondEndpoint()); firstEndpoint.changeFrame(screenFrame); secondEndpoint.changeFrame(screenFrame); drawLineSegment(pixelate(firstEndpoint.getX()), pixelate(firstEndpoint.getY()), pixelate(secondEndpoint.getX()), pixelate(secondEndpoint.getY())); }
public void drawLineSegment(PlotterReferenceFrame frame, LineSegment2d lineSegment) { PlotterPoint2d firstEndpoint = pointBin[0]; PlotterPoint2d secondEndpoint = pointBin[1]; firstEndpoint.setIncludingFrame(frame, lineSegment.getFirstEndpoint()); secondEndpoint.setIncludingFrame(frame, lineSegment.getSecondEndpoint()); firstEndpoint.changeFrame(screenFrame); secondEndpoint.changeFrame(screenFrame); drawLineSegment(pixelate(firstEndpoint.getX()), pixelate(firstEndpoint.getY()), pixelate(secondEndpoint.getX()), pixelate(secondEndpoint.getY())); }
/** * Returns true if lineSegment is Obviously Outside BoundingBox. If returns true, then definitely outside. If returns false, might still be outside. * If intersects, will always return false. * @param candidateRegion * @param lineSegmentInWorld * @return */ private boolean isLineSegmentObviouslyOutsideBoundingBox(PlanarRegion candidateRegion, LineSegment2d lineSegmentInWorld) { BoundingBox3d boundingBox = candidateRegion.getBoundingBox3dInWorld(); double xMin = boundingBox.getXMin(); double yMin = boundingBox.getYMin(); double xMax = boundingBox.getXMax(); double yMax = boundingBox.getYMax(); Point2d firstEndpoint = lineSegmentInWorld.getFirstEndpoint(); Point2d secondEndpoint = lineSegmentInWorld.getSecondEndpoint(); if ((firstEndpoint.getX() < xMin) && (secondEndpoint.getX() < xMin)) return true; if ((firstEndpoint.getX() > xMax) && (secondEndpoint.getX() > xMax)) return true; if ((firstEndpoint.getY() < yMin) && (secondEndpoint.getY() < yMin)) return true; if ((firstEndpoint.getY() > yMax) && (secondEndpoint.getY() > yMax)) return true; return false; }
Point2d segmentEnd = lineSegment.getSecondEndpoint(); double segmentVectorX = segmentEnd.x - segmentStart.x; double segmentVectorY = segmentEnd.y - segmentStart.y;
/** * Projects the input LineSegment2d to the plane defined by this PlanarRegion by translating each vertex in world z. * Then puts each vertex in local frame. In doing so, the length of the rotated lineSegment will actually increase on tilted PlanarRegions. * @param lineSegmentInWorld LineSegment2d to project * @return new projected LineSegment2d */ private LineSegment2d projectLineSegmentVerticallyToRegion(LineSegment2d lineSegmentInWorld) { Point2d[] snappedEndpoints = new Point2d[2]; Point2d originalVertex = lineSegmentInWorld.getFirstEndpoint(); Point3d snappedVertex3d = new Point3d(); // Find the vertex 3d that is snapped to the plane following z-world. snappedVertex3d.setX(originalVertex.getX()); snappedVertex3d.setY(originalVertex.getY()); snappedVertex3d.setZ(getPlaneZGivenXY(originalVertex.getX(), originalVertex.getY())); // Transform to local coordinates fromWorldToLocalTransform.transform(snappedVertex3d); snappedEndpoints[0] = new Point2d(snappedVertex3d.getX(), snappedVertex3d.getY()); originalVertex = lineSegmentInWorld.getSecondEndpoint(); // Find the vertex 3d that is snapped to the plane following z-world. snappedVertex3d.setX(originalVertex.getX()); snappedVertex3d.setY(originalVertex.getY()); snappedVertex3d.setZ(getPlaneZGivenXY(originalVertex.getX(), originalVertex.getY())); // Transform to local coordinates fromWorldToLocalTransform.transform(snappedVertex3d); snappedEndpoints[1] = new Point2d(snappedVertex3d.getX(), snappedVertex3d.getY()); LineSegment2d projectedLineSegment = new LineSegment2d(snappedEndpoints); return projectedLineSegment; }