Package edu.cnu.mdi.geometry
Class Line
java.lang.Object
edu.cnu.mdi.geometry.Line
A three-dimensional parametric line, represented as
p(t) = p0 + t * dp.
The same representation can be used as an infinite line or as a directed line
segment. For an infinite line, t may be any real value. For the
directed segment from p0 to p1, the segment corresponds to
0 <= t <= 1.
- Author:
- heddle
-
Constructor Summary
ConstructorsConstructorDescriptionLine(double[] p1, double[] p2) Creates a line from two arrays containingx,y, andzvalues.Creates a copy of another line.Creates a line from two points.Creates a line through the origin in the direction of a vector. -
Method Summary
Modifier and TypeMethodDescriptionFinds the point on this infinite line closest to a given point.doubleComputes the shortest distance from this infinite line to a point.Gets the midpoint of the directed segment fromp0top1.getDelP()Gets the line direction vectordp = p1 - p0.getP(double t) Gets a point on the parametric line.voidGets a point on the parametric line and stores it in an existing point.getP0()Gets the line's base point.getP1()Gets the endpoint corresponding tot = 1.doubleComputes the line parameter of the point on this infinite line closest to a given point.toString()Returns a string representation of this line.
-
Constructor Details
-
Line
Creates a line from two points.If the line is interpreted as a directed segment, it runs from
potop1.- Parameters:
po- one point on the linep1- another point on the line- Throws:
NullPointerException- if either point isnullIllegalArgumentException- if the two points are coincident, non-finite, or too close to define a stable direction
-
Line
public Line(double[] p1, double[] p2) Creates a line from two arrays containingx,y, andzvalues.- Parameters:
p1- one point as an xyz arrayp2- another point as an xyz array- Throws:
NullPointerException- if either array isnullIndexOutOfBoundsException- if either array has fewer than three valuesIllegalArgumentException- if the two points are coincident or too close to define a stable direction
-
Line
Creates a copy of another line.- Parameters:
line- the line to copy- Throws:
NullPointerException- iflineisnull
-
Line
Creates a line through the origin in the direction of a vector.- Parameters:
v- the direction vector- Throws:
NullPointerException- ifvisnullIllegalArgumentException- ifvis the zero vector or too close to zero to define a stable direction
-
-
Method Details
-
getP0
Gets the line's base point.This is an arbitrary point on an infinite line and the start point if this object is interpreted as a directed segment.
- Returns:
- a copy of the base point
-
getDelP
Gets the line direction vectordp = p1 - p0.- Returns:
- a copy of the direction vector
-
getP1
Gets the endpoint corresponding tot = 1.This is an arbitrary second point on an infinite line and the end point if this object is interpreted as a directed segment.
- Returns:
- the point
p0 + dp
-
getP
Gets a point on the parametric line.- Parameters:
t- the line parameter; use0 <= t <= 1for the finite directed segment- Returns:
- the point
p0 + t*dp
-
getP
Gets a point on the parametric line and stores it in an existing point.- Parameters:
t- the line parameter; use0 <= t <= 1for the finite directed segmentp- upon return, containsp0 + t*dp- Throws:
NullPointerException- ifpisnull
-
distance
Computes the shortest distance from this infinite line to a point.This method ignores segment endpoints. To use the finite segment distance, clamp the parameter returned by
parameterOfClosestPoint(Point)to the interval[0, 1].- Parameters:
p- the point- Returns:
- the perpendicular distance from
pto the infinite line - Throws:
NullPointerException- ifpisnull
-
parameterOfClosestPoint
Computes the line parameter of the point on this infinite line closest to a given point.- Parameters:
p- the point- Returns:
- the parameter
tfor the closest pointp0 + t*dp - Throws:
NullPointerException- ifpisnull
-
closestPointOnLine
Finds the point on this infinite line closest to a given point.- Parameters:
p- the given point- Returns:
- the closest point on the infinite line
- Throws:
NullPointerException- ifpisnull
-
toString
Returns a string representation of this line. -
getCenter
Gets the midpoint of the directed segment fromp0top1.- Returns:
- the point corresponding to
t = 0.5
-