Package org.opentrafficsim.base.geometry
Interface OtsShape
- All Superinterfaces:
Locatable
- All Known Implementing Classes:
CircleShape,OffsetRectangleShape,PolygonShape,RectangleShape,RoundedRectangleShape
Locatable that provides absolute and relative contours and bounds, both statically and dynamically.
Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Wouter Schakel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default intended number of polygon segments to represent continuous shapes.static final doubleMinimum world margin to click on object line or point objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic Polygon2dboundsAsAbsoluteContour(OtsShape locatable) Generates a polygon as contour based on bounds and location of the locatable.default booleancontains(double x, double y) Returns whether the point is contained within the shape.default booleanReturns whether the point is contained within the shape.default Bounds2dReturns the bounds in world coordinates.default Polygon2dReturns the contour of the object in world coordinates.default Polygon2dgetAbsoluteContour(Duration time) Return the contour of a dynamic object at time 'time' in world coordinates.default doublegetDirZ()default Bounds2dReturns the bounds relative to the location.Returns the contour of the object in relative coordinates.default doublesignedDistance(double x, double y) Signed distance function.default doublesignedDistance(Point2d point) Signed distance function.static Transform2dtoAbsoluteTransform(Point2d location) Returns a transformation by which relative coordinates can be translated and rotated to the frame of the possibly oriented location around which bounds are defined.static Transform2dtoRelativeTransform(Point2d location) Returns a transformation by which absolute coordinates can be translated and rotated to the frame of the possibly oriented location around which bounds are defined.static PolyLine2dtransformLine(PolyLine2d line, Point2d location) Transform the line by location, which may also be anOrientedPointfor rotation.
-
Field Details
-
WORLD_MARGIN_LINE
static final double WORLD_MARGIN_LINEMinimum world margin to click on object line or point objects.- See Also:
-
DEFAULT_POLYGON_SEGMENTS
static final int DEFAULT_POLYGON_SEGMENTSThe default intended number of polygon segments to represent continuous shapes.- See Also:
-
-
Method Details
-
getLocation
DirectedPoint2d getLocation()- Specified by:
getLocationin interfaceLocatable
-
getAbsoluteContour
Returns the contour of the object in world coordinates.- Returns:
- the contour of the object in world coordinates
-
getAbsoluteContour
Return the contour of a dynamic object at time 'time' in world coordinates. The default implementation returns the static contour.- Parameters:
time- simulation time for which we want the shape- Returns:
- the shape of the object at time 'time'
-
getRelativeContour
Polygon2d getRelativeContour()Returns the contour of the object in relative coordinates.- Returns:
- the contour of the object in relative coordinates
-
getRelativeBounds
Returns the bounds relative to the location. The default implementation returns the bounds of the contour.- Specified by:
getRelativeBoundsin interfaceLocatable- Returns:
- bounds relative to the location.
-
contains
Returns whether the point is contained within the shape. The default implementation calculates this based on the contour.- Parameters:
point- point- Returns:
- whether the point is contained within the shape
-
contains
default boolean contains(double x, double y) Returns whether the point is contained within the shape. The default implementation calculates this based on the contour.- Parameters:
x- x coordinate of the pointy- y coordinate of the point- Returns:
- whether the point is contained within the shape
-
getAbsoluteBounds
Returns the bounds in world coordinates.- Returns:
- bounds in world coordinates.
-
getDirZ
default double getDirZ() -
signedDistance
Signed distance function. The point must be relative. Negative distances returned are inside the bounds, with the absolute value of the distance towards the edge. The default implementation is based on the polygon representation, which is expensive.- Parameters:
point- point for which distance is returned.- Returns:
- distance from point to these bounds.
-
signedDistance
default double signedDistance(double x, double y) Signed distance function. The point must be relative. Negative distances returned are inside the bounds, with the absolute value of the distance towards the edge. The default implementation is based on the polygon representation, which is expensive.- Parameters:
x- x coordinate of the pointy- y coordinate of the point- Returns:
- distance from point to these bounds.
-
boundsAsAbsoluteContour
Generates a polygon as contour based on bounds and location of the locatable.- Parameters:
locatable- locatable- Returns:
- contour
-
transformLine
Transform the line by location, which may also be anOrientedPointfor rotation.- Parameters:
line- linelocation- location, which may also be anOrientedPointfor rotation- Returns:
- transformed line
-
toRelativeTransform
Returns a transformation by which absolute coordinates can be translated and rotated to the frame of the possibly oriented location around which bounds are defined.- Parameters:
location- location (can be anOriented).- Returns:
- transformation.
-
toAbsoluteTransform
Returns a transformation by which relative coordinates can be translated and rotated to the frame of the possibly oriented location around which bounds are defined.- Parameters:
location- location (can be anOriented).- Returns:
- transformation.
-