Package org.djutils.draw.point
Class OrientedPoint2d
- java.lang.Object
-
- org.djutils.draw.point.Point2d
-
- org.djutils.draw.point.OrientedPoint2d
-
- All Implemented Interfaces:
Serializable
,Drawable<Point2d,Space2d>
,Drawable2d
,Oriented<OrientedPoint2d>
,Oriented2d<OrientedPoint2d>
,Point<Point2d,Space2d>
public class OrientedPoint2d extends Point2d implements Oriented2d<OrientedPoint2d>
The OrientedPoint2d is a point in a 2-dimensional space with an orientation vector, which is specified in terms of its counter-clockwise rotation around the point in radians.Copyright (c) 2020-2021 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 OrientedPoint2d(double[] xy, double dirZ)
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.OrientedPoint2d(double x, double y)
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.OrientedPoint2d(double x, double y, double dirZ)
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.OrientedPoint2d(Point2D point, double dirZ)
Construct an immutable directed point from an AWT Point2D, and a direction, stored with double precision.OrientedPoint2d(Point2d point, double dirZ)
Construct an immutable directed point with a direction from another Point, stored with double precision.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OrientedPoint2d
abs()
Return a new Point with absolute coordinate values.boolean
epsilonEquals(OrientedPoint2d other, double epsilonCoordinate, double epsilonRotation)
Compare this Oriented with another Oriented with specified tolerances in the coordinates and the angles.boolean
equals(Object obj)
double
getDirZ()
Return the rotation around the z-axis in radians.Iterator<? extends OrientedPoint2d>
getPoints()
Retrieve, or generate all points that make up the object.int
hashCode()
OrientedPoint2d
interpolate(OrientedPoint2d otherPoint, double fraction)
Interpolate towards another Point with a fraction.OrientedPoint2d
neg()
Return a new Point with negated coordinate values.OrientedPoint2d
normalize()
Return a new Point with a distance of 1 to the origin.OrientedPoint2d
rotate(double rotateZ)
Return a new OrientedPoint with an in-place rotation around the z-axis by the provided delta.OrientedPoint2d
scale(double factor)
Return a new Point with the coordinates of this point scaled by the provided factor.String
toString()
Return a string representation of the point.String
toString(int fractionDigits)
Return a string representation of the point with a certain number of fraction digits for the coordinates.OrientedPoint2d
translate(double dx, double dy)
Return a new Point with a translation by the provided dx and dy.OrientedPoint3d
translate(double dx, double dy, double z)
Return a new Point3d with a translation by the provided delta-x, delta-y and deltaZ.-
Methods inherited from class org.djutils.draw.point.Point2d
circleIntersections, closestPointOnLine, closestPointOnLine, closestPointOnSegment, directionTo, distance, distanceSquared, epsilonEquals, getBounds, getX, getY, interpolate, intersectionOfLines, intersectionOfLineSegments, size, toPoint2D
-
-
-
-
Constructor Detail
-
OrientedPoint2d
public OrientedPoint2d(double x, double y) throws IllegalArgumentException
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.- Parameters:
x
- double; the x coordinatey
- double; the y coordinate- Throws:
IllegalArgumentException
- when any coordinate is NaN
-
OrientedPoint2d
public OrientedPoint2d(double x, double y, double dirZ) throws IllegalArgumentException
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.- Parameters:
x
- double; the x coordinatey
- double; the y coordinatedirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when any coordinate or dirZ is NaN
-
OrientedPoint2d
public OrientedPoint2d(double[] xy, double dirZ) throws IllegalArgumentException
Construct an immutable directed point with an x and y coordinate, and a direction, stored with double precision.- Parameters:
xy
- double[]; the x and y coordinatedirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
NullPointerException
- when xy is nullIllegalArgumentException
- when the dimension of xy is not 2 or any value in xy is NaN or rotZ is NaN
-
OrientedPoint2d
public OrientedPoint2d(Point2D point, double dirZ) throws IllegalArgumentException
Construct an immutable directed point from an AWT Point2D, and a direction, stored with double precision.- Parameters:
point
- Point2D; an AWT Point2DdirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when any coordinate in point is NaN, or rotZ is NaN
-
OrientedPoint2d
public OrientedPoint2d(Point2d point, double dirZ) throws IllegalArgumentException
Construct an immutable directed point with a direction from another Point, stored with double precision.- Parameters:
point
- Point2d; a point with or without rotationdirZ
- double; the counter-clockwise rotation around the point in radians- Throws:
IllegalArgumentException
- when rotZ is NaN
-
-
Method Detail
-
translate
public OrientedPoint2d translate(double dx, double dy) throws IllegalArgumentException
Return a new Point with a translation by the provided dx and dy.- Overrides:
translate
in classPoint2d
- Parameters:
dx
- double; the horizontal translationdy
- double; the vertical translation- Returns:
- P; a new point with the translated coordinates
- Throws:
IllegalArgumentException
- when dx, or dy is NaN
-
translate
public OrientedPoint3d translate(double dx, double dy, double z) throws IllegalArgumentException
Return a new Point3d with a translation by the provided delta-x, delta-y and deltaZ.- Overrides:
translate
in classPoint2d
- Parameters:
dx
- double; the x translationdy
- double; the y translationz
- double; the z translation- Returns:
- Point2d; a new point with the translated coordinates
- Throws:
IllegalArgumentException
- when dx, dy, or dz is NaN
-
scale
public OrientedPoint2d scale(double factor) throws IllegalArgumentException
Return a new Point with the coordinates of this point scaled by the provided factor.
-
neg
public OrientedPoint2d neg()
Return a new Point with negated coordinate values.
-
abs
public OrientedPoint2d abs()
Return a new Point with absolute coordinate values.
-
normalize
public OrientedPoint2d normalize()
Return a new Point with a distance of 1 to the origin.
-
interpolate
public OrientedPoint2d interpolate(OrientedPoint2d otherPoint, double fraction) throws NullPointerException, IllegalArgumentException
Interpolate towards another Point with a fraction. It is allowed for fraction to be less than zero or larger than 1. In that case the interpolation turns into an extrapolation. DirZ is interpolated using the interpolateShortest method.- Parameters:
otherPoint
- OrientedPoint2d; the other pointfraction
- double; the factor for interpolation towards the other point. When <code>fraction</code> is between 0 and 1, it is an interpolation, otherwise an extrapolation. Iffraction
is 0;this
Point is returned; iffraction
is 1, the otherpoint
is returned- Returns:
- OrientedPoint2d; a new OrientedPoint2d at the requested fraction
- Throws:
NullPointerException
- when otherPoint is nullIllegalArgumentException
- when fraction is NaN
-
rotate
public OrientedPoint2d rotate(double rotateZ) throws IllegalArgumentException
Return a new OrientedPoint with an in-place rotation around the z-axis by the provided delta. The resulting rotation will be normalized between -π and π.- Parameters:
rotateZ
- double; the rotation around the z-axis- Returns:
- OrientedPoint; a new point with the same coordinates and applied rotation
- Throws:
IllegalArgumentException
- when deltaRotZ is NaN
-
getDirZ
public double getDirZ()
Return the rotation around the z-axis in radians.- Specified by:
getDirZ
in interfaceOriented<OrientedPoint2d>
- Returns:
- double; the rotation around the z-axis in radians
-
getPoints
public Iterator<? extends OrientedPoint2d> getPoints()
Retrieve, or generate all points that make up the object.
-
toString
public String toString()
Return a string representation of the point.
-
toString
public String toString(int fractionDigits)
Return a string representation of the point with a certain number of fraction digits for the coordinates.
-
epsilonEquals
public boolean epsilonEquals(OrientedPoint2d other, double epsilonCoordinate, double epsilonRotation) throws NullPointerException, IllegalArgumentException
Compare this Oriented with another Oriented with specified tolerances in the coordinates and the angles.- Specified by:
epsilonEquals
in interfaceOriented<OrientedPoint2d>
- Parameters:
other
- O; 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 coordinatesepsilonRotation
- 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
-
-