Package org.opentrafficsim.core.geometry
Class OtsGeometryUtil
java.lang.Object
org.opentrafficsim.core.geometry.OtsGeometryUtil
Utility class for OTS geometry.
Copyright (c) 2013-2024 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, Guus Tamminga
-
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 final org.djutils.draw.line.PolyLine2doffsetLine(org.djutils.draw.line.PolyLine2d line, double[] relativeFractions, double[] offsets) Create a line at linearly varying offset from this line.static org.djutils.draw.point.OrientedPoint2doffsetPoint(org.djutils.draw.point.OrientedPoint2d 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, org.djutils.draw.point.Point2d point) Print one Point2d on the console.static StringprintCoordinates(String prefix, org.djutils.draw.point.Point2d[] points, int fromIndex, int toIndex, String separator) Built a string description from part of an array of coordinates.static StringprintCoordinates(String prefix, org.djutils.draw.point.Point2d[] coordinates, String separator) Build a string description from an array of coordinates.static StringprintCoordinates(String prefix, OtsLine2d line, String separator) Build a string description from an OtsLine2d.
-
Method Details
-
printCoordinate
Print one Point2d on the console.- Parameters:
prefix- String; text to put before the outputpoint- Point2d; the coordinate to print- Returns:
- String
-
printCoordinates
public static String printCoordinates(String prefix, org.djutils.draw.point.Point2d[] coordinates, String separator) Build a string description from an array of coordinates.- Parameters:
prefix- String; text to put before the coordinatescoordinates- Point2d[]; the points to printseparator- String; prepended to each coordinate- Returns:
- String; description of the array of coordinates
-
printCoordinates
Build a string description from an OtsLine2d.- Parameters:
prefix- String; text to put before the coordinatesline- OtsLine2d; the line for which to print the pointsseparator- String; prepended to each coordinate- Returns:
- String; description of the OtsLine2d
-
printCoordinates
public static String printCoordinates(String prefix, org.djutils.draw.point.Point2d[] points, int fromIndex, int toIndex, String separator) Built a string description from part of an array of coordinates.- Parameters:
prefix- String; text to put before the outputpoints- OtsPoint3d[]; the coordinates to printfromIndex- int; index of the first coordinate to printtoIndex- int; one higher than the index of the last coordinate to printseparator- String; prepended to each coordinate- Returns:
- String; description of the selected part of the array of coordinates
-
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- double; maximum spatial error.angle- Angle; angle of arc at radius.r- double; critical radius (largest radius).- Returns:
- int; number of segments to use for a given maximum spatial error, and radius.
-
offsetPoint
public static org.djutils.draw.point.OrientedPoint2d offsetPoint(org.djutils.draw.point.OrientedPoint2d point, double offset) 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- OrientedPoint2d; point.offset- double; offset, negative values are to the right.- Returns:
- OrientedPoint2d; offset point.
-
offsetLine
public static final org.djutils.draw.line.PolyLine2d offsetLine(org.djutils.draw.line.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- PolyLine2d; reference line.relativeFractions- double[]; positional fractions for which the offsets have to be generatedoffsets- double[]; offsets at the relative positions (positive value is Left, negative value is Right)- Returns:
- PolyLine2d; 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
-