Package org.opentrafficsim.core.geometry
Class OTSGeometryUtil
- java.lang.Object
-
- org.opentrafficsim.core.geometry.OTSGeometryUtil
-
public final class OTSGeometryUtil extends Object
Utility class for OTS geometry.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
$LastChangedDate: 2015-07-16 10:20:53 +0200 (Thu, 16 Jul 2015) $, @version $Revision: 1124 $, by $Author: pknoppers $, initial version Jul 22, 2015
BSD-style license. See OpenTrafficSim License.- Author:
- Alexander Verbraeck, Peter Knoppers, Guus Tamminga
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleaverageAngle(double angle1, double angle2)Compute the average of two angles.static <U extends Unit<U>,S extends DoubleScalarInterface<U,S>,V extends DoubleVectorInterface<U,S,V>>
VdoubleVector(Point3d point, U unit)Create a DENSE DoubleVector with the x, y and z values of this Point3d.static doublegetProjectedVertexRadius(PolyLine2d line, int index)Calculates the directional radius at a vertex.static PolyLine3doffsetLine(PolyLine3d reference, double offset)Offset line method for PolyLine3d using only a horizontal offset component, using default values for precision.static PolyLine3doffsetLine(PolyLine3d reference, double[] relativeFractions, double[] offsets)Create a line at linearly varying offset from this line.static StringprintPath(Shape shape)Print a human readable interpretation of a Shape object using default printing precision.static StringprintPath(Shape shape, String format)Print a human readable interpretation of a Shape object.static doubleprojectFractional(PolyLine3d polyLine3d, Direction start, Direction end, double x, double y)Try to project a point on to a PolyLine3d in a continuous fashion.static Path2DtoPath(double translateX, double translateY, Polygon2d polygon)Construct a Path2D object that reflects a Polygon2d with inverted y-coordinates.static Path2DtoPath(double translateX, double translateY, PolyLine2d line)Construct a Path2D object that reflects a PolyLine2d with inverted y-coordinates.static Path2DtoPath(Polygon2d polygon)Construct a Path2D object that reflects a Polygon2d with inverted y-coordinates.static Path2DtoPath(PolyLine2d line)Construct a Path2D object that reflects a PolyLine2d with inverted y-coordinates.static doubleweightedAverageAngle(double[] angles, double[] weights)Compute a weighted average of a number of angles.
-
-
-
Method Detail
-
doubleVector
public static <U extends Unit<U>,S extends DoubleScalarInterface<U,S>,V extends DoubleVectorInterface<U,S,V>> V doubleVector(Point3d point, U unit)
Create a DENSE DoubleVector with the x, y and z values of this Point3d.- Type Parameters:
U- the unit typeS- the corresponding scalar typeV- the corresponding vector type- Parameters:
point- Point3d; the point.unit- U; unit of the values in this OTSPoint3D (and also the display unit of the returned DoubleVector)- Returns:
- DoubleVector; the constructed DoubleVector, size is 3; first value is x, second is y, third is z
-
offsetLine
public static PolyLine3d offsetLine(PolyLine3d reference, double offset)
Offset line method for PolyLine3d using only a horizontal offset component, using default values for precision. The result is reasonable for reasonable reference lines; jagged reference lines or reference lines that self-intersect may yield very bad results.- Parameters:
reference- PolyLine3d; the reference lineoffset- double; the horizontal offset; positive values indicate left of the reference line, negative values indicate right of the reference line- Returns:
- PolyLine3d; a line at the specified offset from the reference line
-
offsetLine
public static PolyLine3d offsetLine(PolyLine3d reference, double[] relativeFractions, double[] offsets)
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:
reference- PolyLine3d; the reference linerelativeFractions- 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:
- Geometry; the Geometry of the line at linearly changing offset of the reference line
-
averageAngle
public static double averageAngle(double angle1, double angle2)Compute the average of two angles. Does the right thing for angles that (after normalization around zero) are on different sides, close to π. Unstable when the difference of the angles is near π.- Parameters:
angle1- double; the first angle (in Radians)angle2- double; the second angle (in Radians)- Returns:
- double; the average of the two angles
-
weightedAverageAngle
public static double weightedAverageAngle(double[] angles, double[] weights)Compute a weighted average of a number of angles. The result is normalized around 0.- Parameters:
angles- double[]; the angles (in Radians)weights- double[]; the weights (non-positive values allowed)- Returns:
- double; the weighted average of the angles
-
projectFractional
public static double projectFractional(PolyLine3d polyLine3d, Direction start, Direction end, double x, double y)
Try to project a point on to a PolyLine3d in a continuous fashion. The result is guaranteed to lie on the (horizontally) closest segment of the PolyLine3d, but it may lie before the start of that segment, or beyond the end of the last segment (i.e. the result may be < 0.0 or > 1.0). Discontinuities in the projection occur when a small change in the location of the point causes a change in the closest segment and that new closest segment is not adjacent to the original closest segment. Discontinuities will also occur where the PolyLine3d contains strictly vertical segments. If the PolyLine3d self-intersects, or has different segments that project on top of one another, there may be several solutions that are equally close. In that case the result is unstable (may depend on floating point rounding errors).- Parameters:
polyLine3d- PolyLine3d; the PolyLine3dstart- Direction; the direction to assume at the start of the polyLine (may be null, in which case this method pretends that the first segment of the line continues before the PolyLine3d in the same direction)end- Direction; the direction to assume at the end of the polyLine (may be null, in which case this method pretends that the last segment continues beyond the PolyLine3d in the same direction)x- double; the point to projecty- double; the point to project- Returns:
- double; the fractional location on the polyLine where the point projects
-
getProjectedVertexRadius
public static double getProjectedVertexRadius(PolyLine2d line, int index)
Calculates the directional radius at a vertex. Negative values reflect right-hand curvature in the design-line direction. The radius at a vertex is calculated as the radius of a circle that is equidistant from both edges connected to the vertex. The circle center is on a line perpendicular to the shortest edge, crossing through the middle of the shortest edge.- Parameters:
line- PolyLine2dindex- int; index of the vertex in range [1 ... size() - 2]- Returns:
- double; radius at the vertex (negative for right-hand curvature)
-
toPath
public static Path2D toPath(PolyLine2d line)
Construct a Path2D object that reflects a PolyLine2d with inverted y-coordinates.- Parameters:
line- PolyLine2d; the line- Returns:
- Path2D; Path2D version of this PolyLine2d
-
toPath
public static Path2D toPath(double translateX, double translateY, PolyLine2d line)
Construct a Path2D object that reflects a PolyLine2d with inverted y-coordinates.- Parameters:
translateX- double; translate X coordinates by this amounttranslateY- double; translate Y coordinates by this amountline- PolyLine2d; the line- Returns:
- Path2D; Path2D version of this PolyLine2d
-
toPath
public static Path2D toPath(Polygon2d polygon)
Construct a Path2D object that reflects a Polygon2d with inverted y-coordinates.- Parameters:
polygon- Polygon2d; the polygon- Returns:
- Path2D; Path2D version of this PolyLine2d
-
toPath
public static Path2D toPath(double translateX, double translateY, Polygon2d polygon)
Construct a Path2D object that reflects a Polygon2d with inverted y-coordinates.- Parameters:
translateX- double; translate X coordinates by this amounttranslateY- double; translate Y coordinates by this amountpolygon- Polygon2d; the polygon- Returns:
- Path2D; Path2D version of this PolyLine2d
-
printPath
public static String printPath(Shape shape)
Print a human readable interpretation of a Shape object using default printing precision.- Parameters:
shape- Shape; the Shape object- Returns:
- String; a human readable interpretation of the Shape object
-
printPath
public static String printPath(Shape shape, String format)
Print a human readable interpretation of a Shape object.- Parameters:
shape- Shape; the Shape objectformat- String; the format conversion that will be used to format all floating point values- Returns:
- String; a human readable interpretation of the Shape object
-
-