Package org.djutils.draw.line
Class Ray2d
java.lang.Object
org.djutils.draw.point.Point2d
org.djutils.draw.point.DirectedPoint2d
org.djutils.draw.line.Ray2d
- All Implemented Interfaces:
Serializable
,Iterable<Point2d>
,Directed<DirectedPoint2d>
,Directed2d<DirectedPoint2d>
,Drawable<Point2d>
,Drawable2d
,Project<Point2d>
,Ray<Ray2d,
,DirectedPoint2d, Point2d> Point<Point2d>
public class Ray2d
extends DirectedPoint2d
implements Drawable2d, Ray<Ray2d,DirectedPoint2d,Point2d>
Ray2d is a half-line in 2d; it has one end point with finite coordinates; the other end point is infinitely far away.
Copyright (c) 2020-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
- See Also:
-
Field Summary
Fields inherited from class org.djutils.draw.point.DirectedPoint2d
dirZ
-
Constructor Summary
ConstructorsConstructorDescriptionRay2d
(double[] xy, double dirZ) Construct a new Ray2d from x and y coordinates in a double[] and a direction.Ray2d
(double x, double y, double dirZ) Construct a new Ray2d.Ray2d
(double x, double y, double throughX, double throughY) Construct a new Ray2d.Construct a new Ray2d.Construct a new Ray2d from an AWT Point2D and a direction.Ray2d
(DirectedPoint2d directedPoint) Construct a new Ray2d.Construct a new Ray2d from a Point2d and a direction.Construct a new Ray2d.Construct a new Ray2d. -
Method Summary
Modifier and TypeMethodDescriptionclosestPointOnRay
(Point2d point) Project a Point on a Ray.boolean
flip()
Flip the direction of the Ray (creates and returns a new Ray instance).Retrieve the bounding rectangle of the object.final double
getDirZ()
Retrieve the angle from the positive x-axis.Get the finite end point of this Ray.getLocationExtended
(double position) Get the location at a position on the line, with its direction.int
hashCode()
iterator()
neg()
Return a new Point with negated coordinate values.projectOrthogonal
(Point2d point) Project a point onto this object.projectOrthogonalExtended
(Point2d point) Project a point onto this object.double
Project a point onto this object.double
Project a point onto this object.int
size()
Retrieve the number of points that make up the object.toString()
Produce a string describing the Drawable using default conversion for the (double) coordinate values.Produce a String describing the Drawable.Methods inherited from class org.djutils.draw.point.DirectedPoint2d
abs, epsilonEquals, interpolate, normalize, rotate, scale, translate, translate
Methods inherited from class org.djutils.draw.point.Point2d
circleIntersections, closestPointOnLine, closestPointOnLine, closestPointOnLine, closestPointOnSegment, closestPointOnSegment, directionTo, distance, distanceSquared, epsilonEquals, fractionalPositionOnLine, getX, getY, interpolate, intersectionOfLines, intersectionOfLines, intersectionOfLines, intersectionOfLineSegments, intersectionOfLineSegments, intersectionOfLineSegments, toPoint2D
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toString
Methods inherited from interface org.djutils.draw.Drawable2d
getDimensions
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.djutils.draw.line.Ray
getLocation
-
Constructor Details
-
Ray2d
public Ray2d(double x, double y, double dirZ) Construct a new Ray2d.- Parameters:
x
- the x coordinate of the finite end point of the rayy
- the y coordinate of the finite end point of the raydirZ
- the angle from the positive X axis direction in radians.- Throws:
ArithmeticException
- whendirZ
isNaN
-
Ray2d
public Ray2d(double[] xy, double dirZ) Construct a new Ray2d from x and y coordinates in a double[] and a direction.- Parameters:
xy
- thex
andy
coordinates of the finite end point in that orderdirZ
- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException
- whenxy
isnull
ArithmeticException
- whenxy
containsNaN
, or rotZ isNaN
IllegalArgumentException
- when the length ofxy
is not 2, ordirZ
is infinite
-
Ray2d
Construct a new Ray2d from an AWT Point2D and a direction.- Parameters:
point
- an AWT Point2DdirZ
- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException
- whenpoint
isnull
ArithmeticException
- when any coordinate inpoint
isNaN
, orrotZ
isNaN
-
Ray2d
Construct a new Ray2d from a Point2d and a direction.- Parameters:
point
- the finite end point of the raydirZ
- the angle from the positive X axis direction in radians.- Throws:
NullPointerException
- whenpoint
isnull
ArithmeticException
- whendirZ
isNaN
-
Ray2d
public Ray2d(double x, double y, double throughX, double throughY) Construct a new Ray2d.- Parameters:
x
- the x coordinate of the finite end point of the rayy
- the y coordinate of the finite end point of the raythroughX
- the x coordinate of another point on the raythroughY
- the y coordinate of another point on the ray- Throws:
IllegalArgumentException
- whenthroughX == x
andthroughY == y
ArithmeticException
- when anythroughX
orthroughY
isNaN
-
Ray2d
Construct a new Ray2d.- Parameters:
point
- the finite end point of the raythroughX
- the x coordinate of another point on the raythroughY
- the y coordinate of another point on the ray- Throws:
NullPointerException
- whenpoint
isnull
ArithmeticException
- when anythroughX
, orthroughY
isNaN
IllegalArgumentException
- whenthroughX == x
andthroughY == y
-
Ray2d
Construct a new Ray2d.- Parameters:
x
- the x coordinate of the finite end point of the rayy
- the y coordinate of the finite end point of the raythroughPoint
- another point on the ray- Throws:
NullPointerException
- whenthroughPoint
isnull
IllegalArgumentException
- whenthroughPoint
is exactly at (x, y)
-
Ray2d
Construct a new Ray2d.- Parameters:
point
- the finite end point of the raythroughPoint
- another point on the ray- Throws:
NullPointerException
- whenthroughPoint
isnull
IllegalArgumentException
- whenthroughPoint
is exactly at(x,y)
-
Ray2d
Construct a new Ray2d.- Parameters:
directedPoint
- point and direction of the new Ray2d
-
-
Method Details
-
getDirZ
public final double getDirZ()Description copied from interface:Directed2d
Retrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond).- Specified by:
getDirZ
in interfaceDirected2d<DirectedPoint2d>
- Specified by:
getDirZ
in interfaceRay<Ray2d,
DirectedPoint2d, Point2d> - Overrides:
getDirZ
in classDirectedPoint2d
- Returns:
- dirZ
-
getEndPoint
Description copied from interface:Ray
Get the finite end point of this Ray.- Specified by:
getEndPoint
in interfaceRay<Ray2d,
DirectedPoint2d, Point2d> - Returns:
- the finite end point of this Ray
-
size
public int size()Description copied from interface:Drawable
Retrieve the number of points that make up the object. -
iterator
- Specified by:
iterator
in interfaceIterable<Point2d>
- Overrides:
iterator
in classDirectedPoint2d
-
getBounds
Description copied from interface:Drawable2d
Retrieve the bounding rectangle of the object.- Specified by:
getBounds
in interfaceDrawable2d
- Overrides:
getBounds
in classPoint2d
- Returns:
- the bounding box of the object
-
neg
Description copied from interface:Point
Return a new Point with negated coordinate values. If this is aDirectedPoint
,dirY
(in case this is aDirectedPoint3d
anddirZ
are negated.- Specified by:
neg
in interfaceDirected<DirectedPoint2d>
- Specified by:
neg
in interfacePoint<Point2d>
- Overrides:
neg
in classDirectedPoint2d
- Returns:
- a new point with negated coordinate values
-
flip
Description copied from interface:Ray
Flip the direction of the Ray (creates and returns a new Ray instance).- Specified by:
flip
in interfaceRay<Ray2d,
DirectedPoint2d, Point2d> - Returns:
- Ray at the same location, but with
dirZ
(in case of a Ray3d) incremented by π anddirY
subtracted from π
-
getLocationExtended
Description copied from interface:Ray
Get the location at a position on the line, with its direction. Position must be a finite value- Specified by:
getLocationExtended
in interfaceRay<Ray2d,
DirectedPoint2d, Point2d> - Parameters:
position
- the position on the line for which to calculate the point on the line- Returns:
- a ray with the same direction as this ray
-
closestPointOnRay
Description copied from interface:Ray
Project a Point on a Ray. If the the projected points lies outside the ray, the start point of the ray is returned. Otherwise the closest point on the ray is returned.
Adapted from example code published by Paul Bourke.- Specified by:
closestPointOnRay
in interfaceRay<Ray2d,
DirectedPoint2d, Point2d> - Parameters:
point
- the point to project onto the segment- Returns:
- either the start point, or DirectedPoint that lies somewhere on this Ray
-
projectOrthogonal
Description copied from interface:Project
Project a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment,null
is returned.- Specified by:
projectOrthogonal
in interfaceProject<Point2d>
- Parameters:
point
- the point- Returns:
- the projection of the point (may be null if no sensible projection is possible). If the result is not
null
; the result lies somewhere on this object.
-
projectOrthogonalExtended
Description copied from interface:Project
Project a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
projectOrthogonalExtended
in interfaceProject<Point2d>
- Parameters:
point
- the point- Returns:
- the projection of the point. This result cannot be
null
, but it may not lie on this object, but, in stead, lie on a line, or plane that extends this object
-
projectOrthogonalFractional
Description copied from interface:Project
Project a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned. If there is no valid solution on the closest segment,NaN
is returned.- Specified by:
projectOrthogonalFractional
in interfaceProject<Point2d>
- Parameters:
point
- the point- Returns:
- the fractional position of the projection of the point (may be
NaN
if no sensible projection is possible). If the result is notNaN
; the result lies somewhere on this object.
-
projectOrthogonalFractionalExtended
Description copied from interface:Project
Project a point onto this object. For PolyLines and Polygons, there may be multiple valid solutions. In that case the solution that lies on the closest segment is returned.- Specified by:
projectOrthogonalFractionalExtended
in interfaceProject<Point2d>
- Parameters:
point
- the point- Returns:
- the fractional position of the projection of the point. This result cannot be
NaN
, but it may be outside the range 0.0 .. 1.0.
-
toString
Description copied from interface:Drawable
Produce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is not allowed to provide a default implementation here.- Specified by:
toString
in interfaceDrawable<Point2d>
- Overrides:
toString
in classDirectedPoint2d
- Returns:
- a string describing the Drawable
-
toString
Description copied from interface:Drawable
Produce a String describing the Drawable.- Specified by:
toString
in interfaceDrawable<Point2d>
- Overrides:
toString
in classDirectedPoint2d
- Parameters:
doubleFormat
- a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName
- iftrue
; the output oftoString
is not prefixed by the class name. This is useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).- Returns:
- textual representation of the Drawable
-
hashCode
public int hashCode()- Overrides:
hashCode
in classDirectedPoint2d
-
equals
- Overrides:
equals
in classDirectedPoint2d
-