maspack.matrix
Class Line

java.lang.Object
  extended by maspack.matrix.Line

public class Line
extends java.lang.Object

Implements a line of 3-space, characterized by a point p and a direction u. This representation is redundant, since a line has only four degrees of freedom. However, the point-direction representation is convenient for parametrically expressing points along the line, as

 x = p + u s
 

Author:
John E. Lloyd

Constructor Summary
Line()
           
Line(double px, double py, double pz, double ux, double uy, double uz)
           
Line(Line line)
           
Line(Point3d p, Vector3d u)
           
 
Method Summary
 double distance(Line line)
          Returns the perpendicular distance of this line to another line.
 double distance(Point3d p1)
          Returns the perpendicular distance of this line to a point
 Vector3d getDirection()
           
 Point3d getOrigin()
           
 void getPluecker(Vector3d u, Vector3d v)
           
 double intersectPlane(Point3d p, Plane plane)
          Finds the intersection of this line with a plane.
 void inverseTransform(AffineTransform3dBase X)
          Applies an inverse affine transformation to this line, in place.
 void inverseTransform(AffineTransform3dBase X, Line line)
          Applies an inverse affine transformation to a specified line and places the result in this line.
 double nearestPoint(Point3d p, Line line)
          Finds the nearest point on this line to another line.
 double nearestPoint(Point3d pr, Vector3d p1)
          Returns the nearest point on this line to another point.
 void scan(ReaderTokenizer rtok)
          Sets this line to values read from a ReaderTokenizer.
 void set(double px, double py, double pz, double ux, double uy, double uz)
           
 void set(Line line)
           
 void set(Point3d p, Vector3d u)
           
 void setDirection(double x, double y, double z)
           
 void setDirection(Vector3d u)
           
 void setOrigin(double x, double y, double z)
           
 void setOrigin(Point3d p)
           
 void setPoints(Point3d p0, Point3d p1)
           
 java.lang.String toString()
          Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction.
 java.lang.String toString(NumberFormat fmt)
          Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction.
 java.lang.String toString(java.lang.String fmtStr)
          Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction.
 void transform(AffineTransform3dBase X)
          Applies an affine transformation to this line, in place.
 void transform(AffineTransform3dBase X, Line line)
          Applies an affine transformation to a specified line and places the result in this line.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line()

Line

public Line(Point3d p,
            Vector3d u)

Line

public Line(Line line)

Line

public Line(double px,
            double py,
            double pz,
            double ux,
            double uy,
            double uz)
Method Detail

set

public void set(Point3d p,
                Vector3d u)

set

public void set(double px,
                double py,
                double pz,
                double ux,
                double uy,
                double uz)

set

public void set(Line line)

getOrigin

public Point3d getOrigin()

getDirection

public Vector3d getDirection()

setOrigin

public void setOrigin(Point3d p)

setOrigin

public void setOrigin(double x,
                      double y,
                      double z)

setPoints

public void setPoints(Point3d p0,
                      Point3d p1)

setDirection

public void setDirection(Vector3d u)

setDirection

public void setDirection(double x,
                         double y,
                         double z)

getPluecker

public void getPluecker(Vector3d u,
                        Vector3d v)

transform

public void transform(AffineTransform3dBase X)
Applies an affine transformation to this line, in place.

Parameters:
X - affine transformation

inverseTransform

public void inverseTransform(AffineTransform3dBase X)
Applies an inverse affine transformation to this line, in place.

Parameters:
X - affine transformation

transform

public void transform(AffineTransform3dBase X,
                      Line line)
Applies an affine transformation to a specified line and places the result in this line.

Parameters:
X - affine transformation
line - line to transform

inverseTransform

public void inverseTransform(AffineTransform3dBase X,
                             Line line)
Applies an inverse affine transformation to a specified line and places the result in this line.

Parameters:
X - affine transformation
line - line to transform

distance

public double distance(Point3d p1)
Returns the perpendicular distance of this line to a point

Parameters:
p1 - point to find distance to
Returns:
distance of the point from this line

distance

public double distance(Line line)
Returns the perpendicular distance of this line to another line.

Parameters:
line - line to find distance to
Returns:
distance of the line from this line

nearestPoint

public double nearestPoint(Point3d pr,
                           Vector3d p1)
Returns the nearest point on this line to another point.

Parameters:
pr - returns nearest point value
p1 - point to find nearest point to
Returns:
signed distance of the nearest point from the origin along the direction

nearestPoint

public double nearestPoint(Point3d p,
                           Line line)
Finds the nearest point on this line to another line. If the lines are parallel, then this line's origin is returned.

Parameters:
p - returns the nearest point value
line - line to find nearest point to
Returns:
signed distance of the nearest point from the origin along the direction

intersectPlane

public double intersectPlane(Point3d p,
                             Plane plane)
Finds the intersection of this line with a plane. If the line and the plane are parallel, then the intersection is set to this line's origin value and the method returns infinity.

Parameters:
p - returns the intersection point
plane - plane to intersect with
Returns:
signed distance along direction from the origin to the intersection point

toString

public java.lang.String toString()
Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction.

Overrides:
toString in class java.lang.Object
Returns:
String representation

toString

public java.lang.String toString(java.lang.String fmtStr)
Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction. Each element is formatted using a C printf style format string. For a description of the format string syntax, see NumberFormat.

Parameters:
fmtStr - numeric format specification
Returns:
String representation of this vector

toString

public java.lang.String toString(NumberFormat fmt)
Returns a String representation of this Line, consisting of the x, y, and z coordinates of the origin, followed by the coordinates of the direction. Each element is formatted using a C printf style as decribed by the parameter NumberFormat. When called numerous times, this routine can be more efficient than toString(String), because the NumberFormat does not need to be recreated each time from a specification string.

Parameters:
fmt - numeric format
Returns:
String representation of this line

scan

public void scan(ReaderTokenizer rtok)
          throws java.io.IOException
Sets this line to values read from a ReaderTokenizer. The input should consist of a sequence of six numbers, separated by white space and optionally surrounded by square brackets [ ]. These numbers give the coordinates of the line origin and direction, repsectively.

Parameters:
rtok - Tokenizer from which line values are read. Number parsing should be enabled.
Throws:
java.io.IOException - if an I/O or formatting error is encountered