public class LineSegment1D extends java.lang.Object implements us.ihmc.euclid.interfaces.Clearable, us.ihmc.euclid.interfaces.Settable<LineSegment1D>, us.ihmc.euclid.interfaces.EpsilonComparable<LineSegment1D>, us.ihmc.euclid.interfaces.GeometricallyComparable<LineSegment1D>
Constructor and Description |
---|
LineSegment1D()
Default constructor that initializes both endpoints of this line segment to
Double.NaN . |
LineSegment1D(double[] endpoints)
Initializes this line segment to have the given endpoints.
|
LineSegment1D(double firstEndpoint,
double secondEndpoint)
Initializes this line segment to have the given endpoints.
|
LineSegment1D(LineSegment1D other)
Creates a new line segment 1D and initializes it to
other . |
Modifier and Type | Method and Description |
---|---|
LineSegment1D |
computeOverlap(LineSegment1D other)
Computes the overlap between this line segment and the other line segment and stores the result
in
intersectionToPack . |
boolean |
computeOverlap(LineSegment1D other,
LineSegment1D intersectionToPack)
Computes the overlap between this line segment and the other line segment and stores the result
in
intersectionToPack . |
boolean |
containsNaN() |
double |
distance(double point)
Calculates the distance between the query and the closest endpoint.
|
boolean |
epsilonEquals(LineSegment1D other,
double epsilon)
Tests on a per-component basis on both endpoints if this line segment is equal to
other
with the tolerance epsilon . |
boolean |
equals(LineSegment1D other)
Tests on a per component basis, if this line segment 1D is exactly equal to
other . |
boolean |
equals(java.lang.Object object)
Tests if the given
object 's class is the same as this, in which case the method returns
equals(LineSegment1D) , it returns false otherwise. |
void |
extendSegmentToPoint(double point)
Extends this line segment to include the given point.
|
boolean |
geometricallyEquals(LineSegment1D other,
double epsilon)
Compares
this to other to determine if the two line segments are geometrically
similar. |
double |
getFirstEndpoint()
Gets the coordinate of this line segment's first endpoint.
|
double |
getMaxPoint()
Gets the highest coordinate of this line segment.
|
double |
getMidPoint()
Calculates the coordinate of the point located in the middle of this line segment.
|
double |
getMinPoint()
Gets the lowest coordinate of this line segment.
|
double |
getSecondEndpoint()
Gets the coordinate of this line segment's second endpoint.
|
boolean |
isAfter(double point)
Tests if the given point is located outside this line segment and that this line segment is point
toward the point.
|
boolean |
isBefore(double point)
Tests if the given point is located outside this line segment and that this line segment is point
away from the point.
|
boolean |
isBetweenEndpoints(double point,
double epsilon)
Tests whether the given point is located between the two endpoints with a given conservative
tolerance
epsilon : |
boolean |
isBetweenEndpointsExclusive(double point)
Tests if this line segment contains the given
point . |
boolean |
isBetweenEndpointsExclusive(LineSegment1D other)
Tests if this line segment entirely contains the given line segment
other . |
boolean |
isBetweenEndpointsInclusive(double point)
Tests if this line segment contains the given
point . |
boolean |
isBetweenEndpointsInclusive(LineSegment1D other)
Tests if this line segment entirely contains the given line segment
other . |
boolean |
isOverlappingExclusive(LineSegment1D other)
Tests if this line segment and the other overlap or not.
|
boolean |
isOverlappingInclusive(LineSegment1D other)
Tests if this line segment and the other overlap or not.
|
double |
length()
Calculates the (absolute) length of this line segment.
|
void |
set(double[] endpoints)
Redefines this line segment with new endpoints.
|
void |
set(double firstEndpoint,
double secondEndpoint)
Sets this line segment's endpoints.
|
void |
set(LineSegment1D other) |
void |
setFirstEndpoint(double firstEndpoint)
Sets the first endpoint of this line segment.
|
void |
setMaxPoint(double newMaxPoint)
Updates the endpoint of this line segment with the highest coordinate.
|
void |
setMinPoint(double newMinPoint)
Updates the endpoint of this line segment with the lowest coordinate.
|
void |
setSecondEndpoint(double secondEndpoint)
Sets the second endpoint of this line segment.
|
void |
setToNaN() |
void |
setToZero() |
double |
signedDistance(double point)
Calculates the distance between the query and the closest endpoint.
|
LineSegment2D |
toLineSegment2d(us.ihmc.euclid.tuple2D.interfaces.Point2DReadOnly zero2d,
us.ihmc.euclid.tuple2D.interfaces.Vector2DReadOnly direction2d)
Compute the 2D equivalent of this line segment.
|
LineSegment3D |
toLineSegment3d(Line3DReadOnly line3d)
Compute the 3D equivalent of this line segment.
|
LineSegment3D |
toLineSegment3d(us.ihmc.euclid.tuple3D.interfaces.Point3DReadOnly zero3d,
us.ihmc.euclid.tuple3D.interfaces.Vector3DReadOnly direction3d)
Compute the 3D equivalent of this line segment.
|
java.lang.String |
toString()
Provides a
String representation of this line segment 1D as follows:Line segment 1D: 1st endpoint = (x), 2nd endpoint = (x) |
public LineSegment1D()
Double.NaN
.public LineSegment1D(double firstEndpoint, double secondEndpoint)
firstEndpoint
- coordinate of the first endpoint of this line segment.secondEndpoint
- coordinate of the second endpoint of this line segment.public LineSegment1D(LineSegment1D other)
other
.other
- the other line segment used to initialize this line segment. Not modified.public LineSegment1D(double[] endpoints)
endpoints
- a two-element array containing in order the first and second endpoints for this
line segment. Not modified.java.lang.IllegalArgumentException
- if the given array has a length different than 2.public boolean computeOverlap(LineSegment1D other, LineSegment1D intersectionToPack)
intersectionToPack
.
Edge cases:
false
and
intersecitonToPack
remains unchanged.
other
- the other line segment. Not modified.intersectionToPack
- line segment used to store the result. Modified.public LineSegment1D computeOverlap(LineSegment1D other)
intersectionToPack
.
Edge cases:
false
and
intersecitonToPack
remains unchanged.
WARNING: This method generates garbage.
other
- the other line segment. Not modified.null
if the line segments do not
overlap.public boolean isOverlappingInclusive(LineSegment1D other)
Edge cases:
other
- the query. Not modified.true
if the two line segments overlap, false
otherwise.public boolean isOverlappingExclusive(LineSegment1D other)
Edge cases:
other
- the query. Not modified.true
if the two line segments overlap, false
otherwise.public boolean isBetweenEndpointsInclusive(LineSegment1D other)
other
.
Edge cases:
other
.
other
- the query. Not modified.true
if this line segment contains other
, false
otherwise.public boolean isBetweenEndpointsExclusive(LineSegment1D other)
other
.
Edge cases:
other
.
other
- the query. Not modified.true
if this line segment contains other
, false
otherwise.public boolean isBetweenEndpointsInclusive(double point)
point
.
Edge cases:
point
- the query.true
if this line segment contains point
, false
otherwise.public boolean isBetweenEndpointsExclusive(double point)
point
.
Edge cases:
point
- the query.true
if this line segment contains point
, false
otherwise.public boolean isBetweenEndpoints(double point, double epsilon)
epsilon
:
epsilon > 0
, the point has to be between the endpoints and at a minimum distance
of epsilon * this.length()
from the closest endpoint.
epsilon < 0
, the point has to be between the endpoints or at a maximum distance of
-epsilon * this.length()
from the closest endpoint.
epsilon = 0
, the point has to be between the endpoints or equal to one of the
endpoints.
point
- the query.epsilon
- the tolerance to use for this test. If positive, the test becomes less
restrictive. If negative, the test becomes more conservative.true
if the point is considered to be between this line segment's endpoints,
false
otherwise.public double signedDistance(double point)
If the point is located between the endpoints of this line segment, the returned value of the distance is negative.
point
- the query.public double distance(double point)
If the point is located between the endpoints of this line segment, this method returns 0.
point
- the query.public void extendSegmentToPoint(double point)
If the point is between this line segment's endpoints, this line segment remains unchanged.
point
- the point to be included by extended this line segment.public boolean isBefore(double point)
point
- the query.true
if the point is located before this line segment, false
if the point
is located between the endpoints of this line segment or if this line segment is pointed
toward the point.public boolean isAfter(double point)
point
- the query.true
if the point is located after this line segment, false
if the point
is located between the endpoints of this line segment or if this line segment is pointed
away from the point.public boolean containsNaN()
containsNaN
in interface us.ihmc.euclid.interfaces.Clearable
public void setToNaN()
setToNaN
in interface us.ihmc.euclid.interfaces.Clearable
public void setToZero()
setToZero
in interface us.ihmc.euclid.interfaces.Clearable
public void set(LineSegment1D other)
set
in interface us.ihmc.euclid.interfaces.Settable<LineSegment1D>
public void set(double firstEndpoint, double secondEndpoint)
firstEndpoint
- coordinate of the first endpoint.secondEndpoint
- coordinate of the second endpoint.public void set(double[] endpoints)
endpoints
- a two-element array containing in order the first and second endpoints for this
line segment. Not modified.java.lang.IllegalArgumentException
- if the given array has a length different than 2.public void setFirstEndpoint(double firstEndpoint)
firstEndpoint
- coordinate of the first endpoint.public void setSecondEndpoint(double secondEndpoint)
secondEndpoint
- coordinate of the second endpoint.public void setMinPoint(double newMinPoint)
newMinPoint
- the new coordinate for the endpoint with the lowest coordinate.java.lang.RuntimeException
- if the argument is greater or equal to the endpoint with greatest
coordinate. This prevents to flip this line segment's direction.public void setMaxPoint(double newMaxPoint)
newMaxPoint
- the new coordinate for the endpoint with the highest coordinate.java.lang.RuntimeException
- if the argument is less or equal to the endpoint with lowest coordinate.
This prevents to flip this line segment's direction.public double getFirstEndpoint()
public double getSecondEndpoint()
public double getMaxPoint()
public double getMinPoint()
public double getMidPoint()
public double length()
public LineSegment3D toLineSegment3d(Line3DReadOnly line3d)
endPoint3d = endPoint1d * lineDirection3d + lineStart3d
.line3d
- the 3D line used as reference to compute the 3D line segment.public LineSegment3D toLineSegment3d(us.ihmc.euclid.tuple3D.interfaces.Point3DReadOnly zero3d, us.ihmc.euclid.tuple3D.interfaces.Vector3DReadOnly direction3d)
endPoint3d = endPoint1d * direction3d + zero3d
.zero3d
- position of the 3D equivalent of an endpoint equal to zero.direction3d
- direction toward greater values of endPoint1d
.public LineSegment2D toLineSegment2d(us.ihmc.euclid.tuple2D.interfaces.Point2DReadOnly zero2d, us.ihmc.euclid.tuple2D.interfaces.Vector2DReadOnly direction2d)
endPoint2d = endPoint1d * direction2d + zero2d
.zero2d
- position of the 2D equivalent of an endpoint equal to zero.direction2d
- direction toward greater values of endPoint1d
.public boolean epsilonEquals(LineSegment1D other, double epsilon)
other
with the tolerance epsilon
.epsilonEquals
in interface us.ihmc.euclid.interfaces.EpsilonComparable<LineSegment1D>
other
- the query. Not modified.epsilon
- the tolerance to use.true
if the two line segments are equal, false
otherwise.public boolean geometricallyEquals(LineSegment1D other, double epsilon)
this
to other
to determine if the two line segments are geometrically
similar.
The comparison is based on comparing the line segments' endpoints. Two line segments are considered geometrically equal even if they are defined with opposite direction.
geometricallyEquals
in interface us.ihmc.euclid.interfaces.GeometricallyComparable<LineSegment1D>
other
- the line segment to compare to. Not modified.epsilon
- the tolerance of the comparison.true
if the two line segments represent the same geometry, false
otherwise.public boolean equals(LineSegment1D other)
other
.other
- the other line segment 1D to compare against this. Not modified.true
if the two line segments are exactly equal component-wise, false
otherwise.public boolean equals(java.lang.Object object)
object
's class is the same as this, in which case the method returns
equals(LineSegment1D)
, it returns false
otherwise.equals
in class java.lang.Object
object
- the object to compare against this. Not modified.true
if object
and this are exactly equal, false
otherwise.public java.lang.String toString()
String
representation of this line segment 1D as follows:toString
in class java.lang.Object
String
representing this line segment 1D.