Package org.djutils.draw.line
Class Ray2d
- java.lang.Object
-
- org.djutils.draw.point.Point2d
-
- org.djutils.draw.line.Ray2d
-
- All Implemented Interfaces:
Serializable
,Directed<Ray2d>
,Drawable<Point2d>
,Drawable2d
,Project<Point2d>
,Ray<Ray2d,Point2d>
,Point<Point2d>
public class Ray2d extends Point2d implements Drawable2d, Ray<Ray2d,Point2d>
Ray2d is a half-line; it has one end point with non-infinite coordinates; the other end point is infinitely far away.Copyright (c) 2020-2023 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
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Ray2d(double x, double y, double phi)
Construct a new Ray2d.Ray2d(double x, double y, double throughX, double throughY)
Construct a new Ray2d.Ray2d(double x, double y, Point2d throughPoint)
Construct a new Ray2d.Ray2d(Point2d point, double phi)
Construct a new Ray2d.Ray2d(Point2d point, double throughX, double throughY)
Construct a new Ray2d.Ray2d(Point2d point, Point2d throughPoint)
Construct a new Ray2d.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Point2d
closestPointOnRay(Point2d point)
Project a Point on a Ray.boolean
epsilonEquals(Ray2d other, double epsilonCoordinate, double epsilonDirection)
Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.boolean
equals(Object obj)
Ray2d
flip()
Flip the direction of the Ray (creates and returns a new Ray instance).Bounds2d
getBounds()
Retrieve the bounding rectangle of the object.Point2d
getEndPoint()
Get the finite end point of this Ray.Ray2d
getLocationExtended(double position)
Get the location at a position on the line, with its direction.double
getPhi()
Retrieve the angle from the positive X axis direction in radians.Iterator<Point2d>
getPoints()
Retrieve, or generate all points that make up the object.int
hashCode()
Ray2d
neg()
Return a new Point with negated coordinate values.Point2d
projectOrthogonal(Point2d point)
Project a point onto this object.Point2d
projectOrthogonalExtended(Point2d point)
Project a point onto this object.double
projectOrthogonalFractional(Point2d point)
Project a point onto this object.double
projectOrthogonalFractionalExtended(Point2d point)
Project a point onto this object.int
size()
Retrieve the number of points that make up the object.String
toString()
Produce a string describing the Drawable using default conversion for the (double) coordinate values.String
toString(String doubleFormat, boolean doNotIncludeClassName)
Produce a String describing the Drawable.-
Methods inherited from class org.djutils.draw.point.Point2d
abs, circleIntersections, closestPointOnLine, closestPointOnLine, closestPointOnLine, closestPointOnSegment, closestPointOnSegment, directionTo, distance, distanceSquared, epsilonEquals, fractionalPositionOnLine, getX, getY, interpolate, intersectionOfLines, intersectionOfLines, intersectionOfLines, intersectionOfLineSegments, intersectionOfLineSegments, intersectionOfLineSegments, normalize, scale, toPoint2D, translate, translate
-
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 org.djutils.draw.line.Ray
getLocation
-
-
-
-
Constructor Detail
-
Ray2d
public Ray2d(double x, double y, double phi) throws DrawRuntimeException
Construct a new Ray2d.- Parameters:
x
- double; the x coordinate of the finite end point of the rayy
- double; the y coordinate of the finite end point of the rayphi
- double; the angle from the positive X axis direction in radians.- Throws:
DrawRuntimeException
- when phi is NaN
-
Ray2d
public Ray2d(Point2d point, double phi) throws NullPointerException, DrawRuntimeException
Construct a new Ray2d.- Parameters:
point
- Point2d; the finite end point of the rayphi
- double; the angle from the positive X axis direction in radians.- Throws:
NullPointerException
- when point is nullDrawRuntimeException
- when phi is NaN
-
Ray2d
public Ray2d(double x, double y, double throughX, double throughY) throws DrawRuntimeException
Construct a new Ray2d.- Parameters:
x
- double; the x coordinate of the finite end point of the rayy
- double; the y coordinate of the finite end point of the raythroughX
- double; the x coordinate of another point on the raythroughY
- double; the y coordinate of another point on the ray- Throws:
DrawRuntimeException
- when throughX == x and throughY == y
-
Ray2d
public Ray2d(Point2d point, double throughX, double throughY) throws NullPointerException, DrawRuntimeException
Construct a new Ray2d.- Parameters:
point
- Point2d; the finite end point of the raythroughX
- double; the x coordinate of another point on the raythroughY
- double; the y coordinate of another point on the ray- Throws:
NullPointerException
- when point is nullDrawRuntimeException
- when throughX == point.x and throughY == point.y
-
Ray2d
public Ray2d(double x, double y, Point2d throughPoint) throws NullPointerException, DrawRuntimeException
Construct a new Ray2d.- Parameters:
x
- double; the x coordinate of the finite end point of the rayy
- double; the y coordinate of the finite end point of the raythroughPoint
- Point2d; another point on the ray- Throws:
NullPointerException
- when throughPoint is nullDrawRuntimeException
- when throughPoint is exactly at (x, y)
-
Ray2d
public Ray2d(Point2d point, Point2d throughPoint) throws NullPointerException, DrawRuntimeException
Construct a new Ray2d.- Parameters:
point
- Point2d; the finite end point of the raythroughPoint
- Point2d; another point on the ray- Throws:
NullPointerException
- when point is null or throughPoint is nullDrawRuntimeException
- when throughPoint is exactly at point
-
-
Method Detail
-
getPhi
public final double getPhi()
Retrieve the angle from the positive X axis direction in radians.
-
getEndPoint
public Point2d getEndPoint()
Get the finite end point of this Ray.- Specified by:
getEndPoint
in interfaceRay<Ray2d,Point2d>
- Returns:
- P; the finite end point of this Ray
-
size
public int size()
Retrieve the number of points that make up the object.
-
getPoints
public Iterator<Point2d> getPoints()
Retrieve, or generate all points that make up the object.
-
getBounds
public Bounds2d getBounds()
Retrieve the bounding rectangle of the object.- Specified by:
getBounds
in interfaceDrawable2d
- Overrides:
getBounds
in classPoint2d
- Returns:
- Bounds2d; the bounding box of the object
-
neg
public Ray2d neg()
Return a new Point with negated coordinate values.
-
flip
public Ray2d flip()
Flip the direction of the Ray (creates and returns a new Ray instance).
-
getLocationExtended
public Ray2d getLocationExtended(double position) throws DrawRuntimeException
Get the location at a position on the line, with its direction. Position must be a positive, finite value- Specified by:
getLocationExtended
in interfaceRay<Ray2d,Point2d>
- Parameters:
position
- double; the position on the line for which to calculate the point on the line- Returns:
- R; a ray with the same direction as this ray
- Throws:
DrawRuntimeException
- when position infinite, or NaN.
-
closestPointOnRay
public Point2d closestPointOnRay(Point2d point) throws NullPointerException
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 provided by Paul Bourke.- Specified by:
closestPointOnRay
in interfaceRay<Ray2d,Point2d>
- Parameters:
point
- P; the point to project onto the segment- Returns:
- P; either the start point, or the end point of the segment or a Point2d that lies somewhere in between those two.
- Throws:
NullPointerException
- when point is null
-
projectOrthogonal
public Point2d projectOrthogonal(Point2d point) throws NullPointerException
Project a point onto this object. For PolyLines, 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
- P; the point- Returns:
- P; 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.
- Throws:
NullPointerException
- when point is null;
-
projectOrthogonalExtended
public Point2d projectOrthogonalExtended(Point2d point)
Project a point onto this object. For PolyLines, 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
- P; the point- Returns:
- P; 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
public double projectOrthogonalFractional(Point2d point) throws NullPointerException
Project a point onto this object. For PolyLines, 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:
projectOrthogonalFractional
in interfaceProject<Point2d>
- Parameters:
point
- P; the point- Returns:
- double; the fractional position of the projection of the point (may be NaN if no sensible projection is possible). If the result is not null; the result lies somewhere on this object.
- Throws:
NullPointerException
- when point is null;
-
projectOrthogonalFractionalExtended
public double projectOrthogonalFractionalExtended(Point2d point) throws NullPointerException
Project a point onto this object. For PolyLines, 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
- P; the point- Returns:
- double; 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.
- Throws:
NullPointerException
- when point is null;
-
epsilonEquals
public boolean epsilonEquals(Ray2d other, double epsilonCoordinate, double epsilonDirection) throws NullPointerException, IllegalArgumentException
Compare this Directed with another Directed with specified tolerances in the coordinates and the angles.- Specified by:
epsilonEquals
in interfaceDirected<Ray2d>
- Parameters:
other
- D; the point to compare withepsilonCoordinate
- double; the upper bound of difference for one of the coordinates; use Double.POSITIVE_INFINITY if you do not want to check the coordinatesepsilonDirection
- double; the upper bound of difference for the direction(s); use Double.POSITIVE_INFINITY if you do not want to check the angles- Returns:
- boolean; true if x, y, and z are less than epsilonCoordinate apart, and rotX, rotY and rotZ are less than epsilonRotation apart, otherwise false
- Throws:
NullPointerException
- when point is nullIllegalArgumentException
- epsilonCoordinate or epsilonRotation is NaN or negative
-
toString
public String toString()
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.
-
toString
public String toString(String doubleFormat, boolean doNotIncludeClassName)
Produce a String describing the Drawable.- Specified by:
toString
in interfaceDrawable<Point2d>
- Overrides:
toString
in classPoint2d
- Parameters:
doubleFormat
- String; a format string (something like "%6.3f") which will be used to render every coordinate value)doNotIncludeClassName
- boolean; if true; the output of toString 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:
- String; textual representation of the Drawable
-
-