Package org.opentrafficsim.base.geometry
Class OtsGeometryUtil
java.lang.Object
org.opentrafficsim.base.geometry.OtsGeometryUtil
Utility class for OTS geometry.
Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetNumSegmentsForRadius(double maxSpatialError, org.djunits.value.vdouble.scalar.Angle angle, double r) Returns the number of segments to use for a given maximum spatial error, and radius.static Point2dintersectionOfLinesEps(double line1P1X, double line1P1Y, double line1P2X, double line1P2Y, boolean lowLimitLine1, boolean highLimitLine1, double line2P1X, double line2P1Y, double line2P2X, double line2P2Y, boolean lowLimitLine2, boolean highLimitLine2, double eps) Compute the 2D intersection of two lines.static PolyLine2doffsetLine(PolyLine2d line, double[] relativeFractions, double[] offsets) Create a line at linearly varying offset from this line.static DirectedPoint2doffsetPoint(DirectedPoint2d point, double offset) Returns a point on a line through the given point, perpendicular to the given direction, at the offset distance.static StringprintCoordinate(String prefix, Point2d point) Print one Point2d on the console.static DirectedPoint2dtranslatePoint(DirectedPoint2d point, double distance) Translates a directed point a given distance in its direction.
-
Method Details
-
printCoordinate
Print one Point2d on the console.- Parameters:
prefix- text to put before the outputpoint- the coordinate to print- Returns:
- String
-
getNumSegmentsForRadius
public static int getNumSegmentsForRadius(double maxSpatialError, org.djunits.value.vdouble.scalar.Angle angle, double r) Returns the number of segments to use for a given maximum spatial error, and radius.- Parameters:
maxSpatialError- maximum spatial error.angle- angle of arc at radius.r- critical radius (largest radius).- Returns:
- number of segments to use for a given maximum spatial error, and radius.
-
offsetPoint
Returns a point on a line through the given point, perpendicular to the given direction, at the offset distance. A negative offset is towards the right hand side relative to the direction.- Parameters:
point- point.offset- offset, negative values are to the right.- Returns:
- offset point.
-
translatePoint
Translates a directed point a given distance in its direction.- Parameters:
point- pointdistance- distance- Returns:
- translated point by distance in its direction
-
offsetLine
public static PolyLine2d offsetLine(PolyLine2d line, double[] relativeFractions, double[] offsets) throws OtsGeometryException Create a line at linearly varying offset from this line. The offset may change linearly from its initial value at the start of the reference line via a number of intermediate offsets at intermediate positions to its final offset value at the end of the reference line.- Parameters:
line- reference line.relativeFractions- positional fractions for which the offsets have to be generatedoffsets- offsets at the relative positions (positive value is Left, negative value is Right)- Returns:
- the PolyLine2d of the line at multi-linearly changing offset of the reference line
- Throws:
OtsGeometryException- when this method fails to create the offset line
-
intersectionOfLinesEps
public static Point2d intersectionOfLinesEps(double line1P1X, double line1P1Y, double line1P2X, double line1P2Y, boolean lowLimitLine1, boolean highLimitLine1, double line2P1X, double line2P1Y, double line2P2X, double line2P2Y, boolean lowLimitLine2, boolean highLimitLine2, double eps) Compute the 2D intersection of two lines. Both lines are defined by two points (that should be distinct).- Parameters:
line1P1X- x-coordinate of start point of line 1line1P1Y- y-coordinate of start point of line 1line1P2X- x-coordinate of end point of line 1line1P2Y- y-coordinate of end point of line 1lowLimitLine1- iftrue; the intersection may not lie before the start point of line 1highLimitLine1- iftrue; the intersection may not lie beyond the end point of line 1line2P1X- x-coordinate of start point of line 2line2P1Y- y-coordinate of start point of line 2line2P2X- x-coordinate of end point of line 2line2P2Y- y-coordinate of end point of line 2lowLimitLine2- iftrue; the intersection may not lie before the start point of line 2highLimitLine2- iftrue; the intersection may not lie beyond the end point of line 2eps- tolerance (conservative to find intersections)- Returns:
- the intersection of the two lines, or
nullif the lines are (almost) parallel, or the intersection point lies outside the permitted range - Throws:
ArithmeticException- when any of the parameters isNaN
-