public final class Line extends AbstractHyperplane<Vector2D> implements EmbeddingHyperplane<Vector2D,Vector1D>
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.
Lines
Modifier and Type | Class and Description |
---|---|
static class |
Line.SubspaceTransform
Class containing a transformed line instance along with a subspace (1D) transform.
|
Modifier and Type | Method and Description |
---|---|
double |
abscissa(Vector2D point)
Get the abscissa of the given point on the line.
|
double |
angle(Line other)
Compute the angle in radians between this instance's direction and the direction
of the given line.
|
boolean |
contains(Line line)
Check if this instance completely contains the other line.
|
boolean |
contains(Vector2D p)
Check if the line contains a point.
|
double |
distance(Line line)
Compute the shortest distance between this instance and
the given line.
|
double |
distance(Vector2D p)
Compute the distance between the instance and a point.
|
boolean |
eq(Line other,
Precision.DoubleEquivalence precision)
Return true if this instance should be considered equivalent to the argument, using the
given precision context for comparison.
|
boolean |
equals(Object obj) |
double |
getAngle()
Get the angle of the line in radians with respect to the abscissa (+x) axis.
|
Vector2D.Unit |
getDirection()
Get the direction of the line.
|
Vector2D |
getOffsetDirection()
Get the offset direction of the line.
|
Vector2D |
getOrigin()
Get the line origin point.
|
double |
getOriginOffset()
Get the signed distance from the origin of the 2D space to the
closest point on the line.
|
int |
hashCode() |
Vector2D |
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 |
offset(Line line)
Get the offset (oriented distance) of the given line relative to this instance.
|
double |
offset(Vector2D point) |
Vector2D |
pointAt(double abscissa,
double offset)
Get one point from the plane, relative to the coordinate system
of the line.
|
Vector2D |
project(Vector2D point) |
Ray |
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.
|
Ray |
rayFrom(Vector2D startPoint)
Create a new ray instance that starts at the projection of the given point
and continues in the direction of the line to infinity.
|
Line |
reverse() |
ReverseRay |
reverseRayTo(double endLocation)
Create a new convex line subset that starts at infinity and continues along
the line up to the given 1D location.
|
ReverseRay |
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 |
segment(double a,
double b)
Create a new line segment from the given 1D interval.
|
Segment |
segment(Vector2D a,
Vector2D b)
Create a new line segment from two points.
|
boolean |
similarOrientation(Hyperplane<Vector2D> other) |
LineConvexSubset |
span() |
Line.SubspaceTransform |
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.
|
Vector2D |
toSpace(double abscissa)
Convert the given abscissa value (1D location on the line)
into a 2D point.
|
Vector2D |
toSpace(Vector1D point) |
String |
toString() |
Vector1D |
toSubspace(Vector2D point) |
Line |
transform(Transform<Vector2D> transform) |
classify, getPrecision
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
classify
toSpace, toSubspace
public double getAngle()
[0, 2pi)
.[0, 2pi)
public Vector2D.Unit getDirection()
public Vector2D getOffsetDirection()
public Vector2D getOrigin()
public double getOriginOffset()
public Line reverse()
reverse
in interface Hyperplane<Vector2D>
public Line transform(Transform<Vector2D> transform)
transform
in interface Hyperplane<Vector2D>
public Line.SubspaceTransform subspaceTransform(Transform<Vector2D> transform)
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 spaceAt the end of execution, the points
a
(which was transformed using the original
2D transform) and b
(which was transformed in 1D using the subspace transform)
are equivalent.transform
- the transform to apply to this instancetransform(Transform)
public LineConvexSubset span()
span
in interface Hyperplane<Vector2D>
public Segment segment(double a, double b)
a
- first 1D location for the intervalb
- second 1D location for the intervalIllegalArgumentException
- if either of the locations is NaN or infiniteLines.segmentFromLocations(Line, double, double)
public Segment segment(Vector2D a, Vector2D b)
a
and b
. The points may be given in any order.a
- first pointb
- second pointIllegalArgumentException
- if either point contains NaN or infinite coordinate valuesLines.segmentFromPoints(Line, Vector2D, Vector2D)
public ReverseRay reverseRayTo(Vector2D endPoint)
endPoint
- point defining the end point of the line subset; the end point
is equal to the projection of this point onto the lineIllegalArgumentException
- if any coordinate in endPoint
is NaN or infiniteLines.reverseRayFromPoint(Line, Vector2D)
public ReverseRay reverseRayTo(double endLocation)
endLocation
- the 1D location of the end of the half-lineIllegalArgumentException
- if endLocation
is NaN or infiniteLines.reverseRayFromLocation(Line, double)
public Ray rayFrom(Vector2D startPoint)
startPoint
- point defining the start point of the ray; the start point
is equal to the projection of this point onto the lineIllegalArgumentException
- if any coordinate in startPoint
is NaN or infiniteLines.rayFromPoint(Line, Vector2D)
public Ray rayFrom(double startLocation)
startLocation
- 1D location defining the start point of the rayIllegalArgumentException
- if startLocation
is NaN or infiniteLines.rayFromLocation(Line, double)
public double abscissa(Vector2D point)
toSubspace(Vector2D)
except that this method
returns a double instead of a Vector1D
.point
- point to compute the abscissa fortoSubspace(Vector2D)
public Vector1D toSubspace(Vector2D point)
toSubspace
in interface Embedding<Vector2D,Vector1D>
public Vector2D toSpace(double abscissa)
abscissa
- value to convertpublic Vector2D intersection(Line other)
other
- other linepublic double angle(Line other)
[-pi, +pi)
. This method
always returns a value, even for parallel or coincident lines.other
- other linepublic Vector2D project(Vector2D point)
project
in interface Hyperplane<Vector2D>
public double offset(Vector2D point)
offset
in interface Hyperplane<Vector2D>
public double offset(Line line)
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.
line
- line to checkdistance(Line)
public boolean similarOrientation(Hyperplane<Vector2D> other)
similarOrientation
in interface Hyperplane<Vector2D>
public Vector2D pointAt(double abscissa, double offset)
abscissa
- desired abscissa (distance along the line) for the pointoffset
- desired offset (distance perpendicular to the line) for the pointpublic boolean contains(Vector2D p)
contains
in interface Hyperplane<Vector2D>
contains
in class AbstractHyperplane<Vector2D>
p
- point to checkpublic boolean contains(Line line)
line
- line to checkpublic double distance(Vector2D p)
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.
p
- to checkpublic double distance(Line line)
line
- line to compute the closest distance tooffset(Line)
public boolean isParallel(Line line)
line
- other line to checkpublic boolean eq(Line other, Precision.DoubleEquivalence precision)
origin
points and make similar angles with the x-axis.other
- the point to compare withprecision
- precision context to use for the comparisonVector2D.eq(Vector2D, Precision.DoubleEquivalence)
Copyright © 2016–2021 The Apache Software Foundation. All rights reserved.