Class Line
- All Implemented Interfaces:
Embedding<Vector2D,
,Vector1D> EmbeddingHyperplane<Vector2D,
,Vector1D> Hyperplane<Vector2D>
An oriented line can be defined either by extending a line segment between two points past these points, by specifying a point and a direction, or by specifying a point and an angle relative to the x-axis.
Since the line oriented, the two half planes on its sides are unambiguously identified as the left half plane and the right half plane. This can be used to identify the interior and the exterior in a simple way when a line is used to define a portion of a polygon boundary.
A line can also be used to completely define a reference frame
in the plane. It is sufficient to select one specific point in the
line (the orthogonal projection of the original reference frame on
the line) and to use the unit vector in the line direction (see
getDirection()
and the orthogonal vector oriented from the
left half plane to the right half plane (see getOffsetDirection()
.
We define two coordinates by the process, the abscissa along
the line, and the offset across the line. All points of the
plane are uniquely identified by these two coordinates. The line is
the set of points at zero offset, the left half plane is the set of
points with negative offsets and the right half plane is the set of
points with positive offsets.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Class containing a transformed line instance along with a subspace (1D) transform. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Vector2D.Unit
The direction of the line as a normalized vector.private final double
The distance between the origin and the line.(package private) static final String
Format string for creating line string representations. -
Constructor Summary
ConstructorsConstructorDescriptionLine
(Vector2D.Unit direction, double originOffset, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Simple constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Get the abscissa of the given point on the line.double
Compute the angle in radians between this instance's direction and the direction of the given line.boolean
Check if this instance completely contains the other line.boolean
Check if the line contains a point.double
Compute the shortest distance between this instance and the given line.double
Compute the distance between the instance and a point.boolean
Return true if this instance should be considered equivalent to the argument, using the given precision context for comparison.boolean
double
getAngle()
Get the angle of the line in radians with respect to the abscissa (+x) axis.Get the direction of the line.Get the offset direction of the line.Get the line origin point.double
Get the signed distance from the origin of the 2D space to the closest point on the line.int
hashCode()
intersection
(Line other) Get the intersection point of the instance and another line.boolean
isParallel
(Line line) Check if the instance is parallel to another line.double
Get the offset (oriented distance) of the given line relative to this instance.double
Get the offset (oriented distance) of a point with respect to this instance.pointAt
(double abscissa, double offset) Get one point from the plane, relative to the coordinate system of the line.Project a point onto this instance.rayFrom
(double startLocation) Create a new ray instance that starts at the given 1D location and continues in the direction of the line to infinity.Create a new ray instance that starts at the projection of the given point and continues in the direction of the line to infinity.reverse()
Return a hyperplane that has the opposite orientation as this instance.reverseRayTo
(double endLocation) Create a new convex line subset that starts at infinity and continues along the line up to the given 1D location.reverseRayTo
(Vector2D endPoint) Create a new convex line subset that starts at infinity and continues along the line up to the projection of the given end point.segment
(double a, double b) Create a new line segment from the given 1D interval.Create a new line segment from two points.boolean
similarOrientation
(Hyperplane<Vector2D> other) Return true if this instance has a similar orientation to the given hyperplane, meaning that they point in generally the same direction.span()
Return aHyperplaneConvexSubset
spanning this entire hyperplane.subspaceTransform
(Transform<Vector2D> transform) Get an object containing the current line transformed by the argument along with a 1D transform that can be applied to subspace points.toSpace
(double abscissa) Convert the given abscissa value (1D location on the line) into a 2D point.Transform a subspace point into a space point.toString()
toSubspace
(Vector2D point) Transform a space point into a subspace point.Transform this instance using the givenTransform
.Methods inherited from class org.apache.commons.geometry.core.partitioning.AbstractHyperplane
classify, getPrecision
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.geometry.core.Embedding
toSpace, toSubspace
Methods inherited from interface org.apache.commons.geometry.core.partitioning.Hyperplane
classify
-
Field Details
-
TO_STRING_FORMAT
Format string for creating line string representations.- See Also:
-
direction
The direction of the line as a normalized vector. -
originOffset
private final double originOffsetThe distance between the origin and the line.
-
-
Constructor Details
-
Line
Line(Vector2D.Unit direction, double originOffset, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Simple constructor.- Parameters:
direction
- The direction of the line.originOffset
- The signed distance between the line and the origin.precision
- Precision context used to compare floating point numbers.
-
-
Method Details
-
getAngle
public double getAngle()Get the angle of the line in radians with respect to the abscissa (+x) axis. The returned angle is in the range[0, 2pi)
.- Returns:
- the angle of the line with respect to the abscissa (+x) axis in the range
[0, 2pi)
-
getDirection
Get the direction of the line.- Returns:
- the direction of the line
-
getOffsetDirection
Get the offset direction of the line. This vector is perpendicular to the line and points in the direction of positive offset values, meaning that it points from the left side of the line to the right when one is looking along the line direction.- Returns:
- the offset direction of the line.
-
getOrigin
Get the line origin point. This is the projection of the 2D origin onto the line and also serves as the origin for the 1D embedded subspace.- Returns:
- the origin point of the line
-
getOriginOffset
public double getOriginOffset()Get the signed distance from the origin of the 2D space to the closest point on the line.- Returns:
- the signed distance from the origin to the line
-
reverse
Return a hyperplane that has the opposite orientation as this instance. That is, the plus side of this instance is the minus side of the returned instance and vice versa.- Specified by:
reverse
in interfaceHyperplane<Vector2D>
- Returns:
- a hyperplane with the opposite orientation
-
transform
Transform this instance using the givenTransform
.- Specified by:
transform
in interfaceHyperplane<Vector2D>
- Parameters:
transform
- object to transform this instance with- Returns:
- a new, transformed hyperplane
-
subspaceTransform
Get an object containing the current line transformed by the argument along with a 1D transform that can be applied to subspace points. The subspace transform transforms subspace points such that their 2D location in the transformed line is the same as their 2D location in the original line after the 2D transform is applied. For example, consider the code below:SubspaceTransform st = line.subspaceTransform(transform); Vector1D subPt = Vector1D.of(1); Vector2D a = transform.apply(line.toSpace(subPt)); // transform in 2D space Vector2D b = st.getLine().toSpace(st.getTransform().apply(subPt)); // transform in 1D space
At the end of execution, the pointsa
(which was transformed using the original 2D transform) andb
(which was transformed in 1D using the subspace transform) are equivalent.- Parameters:
transform
- the transform to apply to this instance- Returns:
- an object containing the transformed line along with a transform that can be applied to subspace points
- See Also:
-
span
Return aHyperplaneConvexSubset
spanning this entire hyperplane. The returned subset contains all points lying in this hyperplane and no more.- Specified by:
span
in interfaceHyperplane<Vector2D>
- Returns:
- a
HyperplaneConvexSubset
containing all points lying in this hyperplane
-
segment
Create a new line segment from the given 1D interval. The returned line segment consists of all points between the two locations, regardless of the order the arguments are given.- Parameters:
a
- first 1D location for the intervalb
- second 1D location for the interval- Returns:
- a new line segment on this line
- Throws:
IllegalArgumentException
- if either of the locations is NaN or infinite- See Also:
-
segment
Create a new line segment from two points. The returned segment represents all points on this line between the projected locations ofa
andb
. The points may be given in any order.- Parameters:
a
- first pointb
- second point- Returns:
- a new line segment on this line
- Throws:
IllegalArgumentException
- if either point contains NaN or infinite coordinate values- See Also:
-
reverseRayTo
Create a new convex line subset that starts at infinity and continues along the line up to the projection of the given end point.- Parameters:
endPoint
- point defining the end point of the line subset; the end point is equal to the projection of this point onto the line- Returns:
- a new, half-open line subset that ends at the given point
- Throws:
IllegalArgumentException
- if any coordinate inendPoint
is NaN or infinite- See Also:
-
reverseRayTo
Create a new convex line subset that starts at infinity and continues along the line up to the given 1D location.- Parameters:
endLocation
- the 1D location of the end of the half-line- Returns:
- a new, half-open line subset that ends at the given 1D location
- Throws:
IllegalArgumentException
- ifendLocation
is NaN or infinite- See Also:
-
rayFrom
Create a new ray instance that starts at the projection of the given point and continues in the direction of the line to infinity.- Parameters:
startPoint
- point defining the start point of the ray; the start point is equal to the projection of this point onto the line- Returns:
- a ray starting at the projected point and extending along this line to infinity
- Throws:
IllegalArgumentException
- if any coordinate instartPoint
is NaN or infinite- See Also:
-
rayFrom
Create a new ray instance that starts at the given 1D location and continues in the direction of the line to infinity.- Parameters:
startLocation
- 1D location defining the start point of the ray- Returns:
- a ray starting at the given 1D location and extending along this line to infinity
- Throws:
IllegalArgumentException
- ifstartLocation
is NaN or infinite- See Also:
-
abscissa
Get the abscissa of the given point on the line. The abscissa represents the distance the projection of the point on the line is from the line's origin point (the point on the line closest to the origin of the 2D space). Abscissa values increase in the direction of the line. This method is exactly equivalent totoSubspace(Vector2D)
except that this method returns a double instead of aVector1D
.- Parameters:
point
- point to compute the abscissa for- Returns:
- abscissa value of the point
- See Also:
-
toSubspace
Transform a space point into a subspace point.- Specified by:
toSubspace
in interfaceEmbedding<Vector2D,
Vector1D> - Parameters:
point
- n-dimension point of the space- Returns:
- lower-dimension point of the subspace corresponding to the specified space point
- See Also:
-
toSpace
Transform a subspace point into a space point. -
toSpace
Convert the given abscissa value (1D location on the line) into a 2D point.- Parameters:
abscissa
- value to convert- Returns:
- 2D point corresponding to the line abscissa value
-
intersection
Get the intersection point of the instance and another line.- Parameters:
other
- other line- Returns:
- intersection point of the instance and the other line or null if there is no unique intersection point (ie, the lines are parallel or coincident)
-
angle
Compute the angle in radians between this instance's direction and the direction of the given line. The return value is in the range[-pi, +pi)
. This method always returns a value, even for parallel or coincident lines.- Parameters:
other
- other line- Returns:
- the angle required to rotate this line to point in the direction of the given line
-
project
Project a point onto this instance.- Specified by:
project
in interfaceHyperplane<Vector2D>
- Parameters:
point
- the point to project- Returns:
- the projection of the point onto this instance. The returned point lies on the hyperplane.
-
offset
Get the offset (oriented distance) of a point with respect to this instance. Points with an offset of zero lie on the hyperplane itself.- Specified by:
offset
in interfaceHyperplane<Vector2D>
- Parameters:
point
- the point to compute the offset for- Returns:
- the offset of the point
-
offset
Get the offset (oriented distance) of the given line relative to this instance. Since an infinite number of distances can be calculated between points on two different lines, this method returns the value closest to zero. For intersecting lines, this will simply be zero. For parallel lines, this will be the perpendicular distance between the two lines, as a signed value.The sign of the returned offset indicates the side of the line that the argument lies on. The offset is positive if the line lies on the right side of the instance and negative if the line lies on the left side of the instance.
- Parameters:
line
- line to check- Returns:
- offset of the line
- See Also:
-
similarOrientation
Return true if this instance has a similar orientation to the given hyperplane, meaning that they point in generally the same direction. This method is not used to determine exact equality of hyperplanes, but rather to determine whether two hyperplanes that contain the same points are parallel (point in the same direction) or anti-parallel (point in opposite directions).- Specified by:
similarOrientation
in interfaceHyperplane<Vector2D>
- Parameters:
other
- the hyperplane to compare with- Returns:
- true if the hyperplanes point in generally the same direction and could possibly be parallel
-
pointAt
Get one point from the plane, relative to the coordinate system of the line. Note that the direction of increasing offsets points to the right of the line. This means that if one pictures the line (abscissa) direction as equivalent to the +x-axis, the offset direction will point along the -y axis.- Parameters:
abscissa
- desired abscissa (distance along the line) for the pointoffset
- desired offset (distance perpendicular to the line) for the point- Returns:
- one point in the plane, with given abscissa and offset relative to the line
-
contains
Check if the line contains a point.- Specified by:
contains
in interfaceHyperplane<Vector2D>
- Overrides:
contains
in classAbstractHyperplane<Vector2D>
- Parameters:
p
- point to check- Returns:
- true if p belongs to the line
-
contains
Check if this instance completely contains the other line. This will be true if the two instances represent the same line, with perhaps different directions.- Parameters:
line
- line to check- Returns:
- true if this instance contains all points in the given line
-
distance
Compute the distance between the instance and a point.This is a shortcut for invoking Math.abs(getOffset(p)), and provides consistency with what is in the org.apache.commons.geometry.euclidean.threed.Line class.
- Parameters:
p
- to check- Returns:
- distance between the instance and the point
-
distance
Compute the shortest distance between this instance and the given line. This value will simply be zero for intersecting lines.- Parameters:
line
- line to compute the closest distance to- Returns:
- the shortest distance between this instance and the given line
- See Also:
-
isParallel
Check if the instance is parallel to another line.- Parameters:
line
- other line to check- Returns:
- true if the instance is parallel to the other line (they can have either the same or opposite orientations)
-
eq
public boolean eq(Line other, org.apache.commons.numbers.core.Precision.DoubleEquivalence precision) Return true if this instance should be considered equivalent to the argument, using the given precision context for comparison. Instances are considered equivalent if they have equivalentorigin
points and make similar angles with the x-axis.- Parameters:
other
- the point to compare withprecision
- precision context to use for the comparison- Returns:
- true if this instance should be considered equivalent to the argument
- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-