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:
Iterable<Point2d>,Directed,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
-
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.booleanflip()Flip the direction of the Ray (creates and returns a new Ray instance).Retrieve the bounding rectangle of the object in absolute coordinates.final doublegetDirZ()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.inthashCode()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.doubleProject a point onto this object.doubleProject a point onto this object.intsize()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, translateMethods 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, toPoint2DMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.draw.Drawable
getPointList, toString, toStringMethods inherited from interface org.djutils.draw.Drawable2d
getDimensionsMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods 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- whendirZisNaN
-
Ray2d
public Ray2d(double[] xy, double dirZ) Construct a new Ray2d from x and y coordinates in a double[] and a direction.- Parameters:
xy- thexandycoordinates of the finite end point in that orderdirZ- the counter-clockwise rotation around the point in radians- Throws:
NullPointerException- whenxyisnullArithmeticException- whenxycontainsNaN, or rotZ isNaNIllegalArgumentException- when the length ofxyis not 2, ordirZis 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- whenpointisnullArithmeticException- when any coordinate inpointisNaN, orrotZisNaN
-
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- whenpointisnullArithmeticException- whendirZisNaN
-
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 == xandthroughY == yArithmeticException- when anythroughXorthroughYisNaN
-
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- whenpointisnullArithmeticException- when anythroughX, orthroughYisNaNIllegalArgumentException- whenthroughX == xandthroughY == 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- whenthroughPointisnullIllegalArgumentException- whenthroughPointis 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- whenthroughPointisnullIllegalArgumentException- whenthroughPointis 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:DirectedRetrieve the angle from the positive x-axis. Positive rotates towards the positive y-axis (and beyond).- Specified by:
getDirZin interfaceDirected- Overrides:
getDirZin classDirectedPoint2d- Returns:
- the angle from the positive x-axis
-
getEndPoint
Description copied from interface:RayGet the finite end point of this Ray.- Specified by:
getEndPointin interfaceRay<Ray2d,DirectedPoint2d, Point2d> - Returns:
- the finite end point of this Ray
-
size
public int size()Description copied from interface:DrawableRetrieve the number of points that make up the object. -
iterator
- Specified by:
iteratorin interfaceIterable<Point2d>- Overrides:
iteratorin classDirectedPoint2d
-
getAbsoluteBounds
Description copied from interface:Drawable2dRetrieve the bounding rectangle of the object in absolute coordinates.- Specified by:
getAbsoluteBoundsin interfaceDrawable2d- Overrides:
getAbsoluteBoundsin classPoint2d- Returns:
- the bounding box of the object in absolute coordinates
-
neg
Description copied from interface:PointReturn a new Point with negated coordinate values. If this is aDirectedPoint,dirY(in case this is aDirectedPoint3danddirZare negated.- Specified by:
negin interfacePoint<Point2d>- Overrides:
negin classDirectedPoint2d- Returns:
- a new point with negated coordinate values
-
flip
Description copied from interface:RayFlip the direction of the Ray (creates and returns a new Ray instance).- Specified by:
flipin interfaceRay<Ray2d,DirectedPoint2d, Point2d> - Returns:
- Ray at the same location, but with
dirZ(in case of a Ray3d) incremented by π anddirYsubtracted from π
-
getLocationExtended
Description copied from interface:RayGet the location at a position on the line, with its direction. Position must be a finite value- Specified by:
getLocationExtendedin 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:RayProject 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:
closestPointOnRayin 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:ProjectProject 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,nullis returned.- Specified by:
projectOrthogonalin 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:ProjectProject 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:
projectOrthogonalExtendedin 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:ProjectProject 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,NaNis returned.- Specified by:
projectOrthogonalFractionalin interfaceProject<Point2d>- Parameters:
point- the point- Returns:
- the fractional position of the projection of the point (may be
NaNif no sensible projection is possible). If the result is notNaN; the result lies somewhere on this object.
-
projectOrthogonalFractionalExtended
Description copied from interface:ProjectProject 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:
projectOrthogonalFractionalExtendedin 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:DrawableProduce 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:
toStringin interfaceDrawable<Point2d>- Overrides:
toStringin classDirectedPoint2d- Returns:
- a string describing the Drawable
-
toString
Description copied from interface:DrawableProduce a String describing the Drawable.- Specified by:
toStringin interfaceDrawable<Point2d>- Overrides:
toStringin classDirectedPoint2d- Parameters:
doubleFormat- a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName- iftrue; the output oftoStringis 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:
hashCodein classDirectedPoint2d
-
equals
- Overrides:
equalsin classDirectedPoint2d
-