maspack.matrix
Class Line3d

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

public class Line3d
extends java.lang.Object

Line3d represents a vector description of a line in three dimensions, which is described by a point on the line and a direction vector.


Constructor Summary
Line3d()
          Creates a Line3d and initializes it to the x axis.
Line3d(double[] values)
          Creates a Line3d and initialises it to the prescribed values.
Line3d(double dirx, double diry, double dirz, double x, double y, double z)
          Creates a Line3d and initialises it to the prescribed values.
Line3d(Line3d line3d)
          Creates a Line3d and initializes it from an existing Line3d.
Line3d(Vector3d direction, Point3d point)
          Creates an Line3d and sets it to the prescribed values.
 
Method Summary
 Point3d closestPoint(Line3d line)
          Finds the point on THIS line that is closest to the supplied line
 Point3d closestPoint(Line3d line, double epsilon)
          Finds the point on THIS line that is closest to the supplied line
static boolean closestPointBetweenLines(Line3d line1, Line3d line2, Point3d pnt1, Point3d pnt2, double epsilon)
           
static boolean closestPointBetweenLines(Vector3d v1, Point3d p1, Vector3d v2, Point3d p2, Point3d out1, Point3d out2, double epsilon)
           
 boolean contains(Point3d point)
          Returns true if supplied point lies exactly on the line
 boolean epsilonContains(Point3d point, double eps)
          Returns true if the supplied point lies on this line within a specified tolerance
 boolean epsilonEquals(Line3d line3d, double eps)
          Returns true if the elements of this Line3d equal those of another Line3d within a prescribed tolerance epsilon.
 boolean equals(Line3d line3d)
          Returns true if the elements of this Line3d equal those of another Line3d exactly.
 boolean equals(java.lang.Object obj)
          Returns true if the supplied object is a Line3d and its elements equal those of this Line3d exactly.
 void get(double[] values)
          Gets the values associated with this Line3d.
 void getDirection(Vector3d d)
          Gets the direction vector for the line
 void getPoint(Vector3d p)
          Gets a point on the line
 Point3d project(Point3d point)
          Finds the closest point to the supplied Point3d that lies on the line.
 void set(double[] values)
          Sets this Line3d to the prescribed values.
 void set(double dirx, double diry, double dirz, double x, double y, double z)
          Sets this Line3d to the prescribed values.
 void set(Line3d line3d)
          Sets this Line3d to the values of another Line3d.
 void set(Vector3d direction, Point3d point)
          Sets this Line3d to the prescribed values.
 void setDirection(Vector3d d)
           
 void setPoint(Point3d p)
           
 java.lang.String toString()
          Returns a String representation of this Line3d, consisting of the components of the direction vector followed by those of the point
 java.lang.String toString(NumberFormat fmt)
          Returns a String representation of this Point3d, consisting of the x, y, and z components of the direction vector, followed by components of the point.
 java.lang.String toString(java.lang.String fmtStr)
          Returns a String representation of this Point3d, consisting of the x, y, and z components of the direction vector, followed by components of the point.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line3d

public Line3d()
Creates a Line3d and initializes it to the x axis.


Line3d

public Line3d(double[] values)
Creates a Line3d and initialises it to the prescribed values. The direction values are normalised.

Parameters:
values - Line3d values given as an array. The x, y, and z components of the direction vector are given by elements 0 through 2, and point is given by elements 3-5.

Line3d

public Line3d(double dirx,
              double diry,
              double dirz,
              double x,
              double y,
              double z)
Creates a Line3d and initialises it to the prescribed values. The direction values are normalised.

Parameters:
dirx - x component of the direction vector
diry - y component of the direction vector
dirz - z component of the direction vector
x - x component of the point
y - y component of the point
z - z component of the point

Line3d

public Line3d(Vector3d direction,
              Point3d point)
Creates an Line3d and sets it to the prescribed values. The direction values are normalised.

Parameters:
direction - direction vector
point - Point on the line

Line3d

public Line3d(Line3d line3d)
Creates a Line3d and initializes it from an existing Line3d.

Parameters:
line3d - Line3d to supply initial values
Method Detail

set

public void set(double dirx,
                double diry,
                double dirz,
                double x,
                double y,
                double z)
Sets this Line3d to the prescribed values. The direction values are normalized.

Parameters:
dirx - x component of direction vector
diry - y component of direction vector
dirz - z component of direction vector
x - x component of point
y - y component of point
z - z component of point

set

public void set(double[] values)
Sets this Line3d to the prescribed values. The direction values are normalized.

Parameters:
values - Line3d values given as an array. The x, y, and z components of the direction vector are given by elements 0 through 2, and the position components by elements 3 through 5

set

public void set(Vector3d direction,
                Point3d point)
Sets this Line3d to the prescribed values. The direction values are normalised.

Parameters:
direction - direction vector
point - point on the line

set

public void set(Line3d line3d)
Sets this Line3d to the values of another Line3d.

Parameters:
line3d - Line3d supplying new values

get

public void get(double[] values)
Gets the values associated with this Line3d.

Parameters:
values - returns the Line3d values. The x, y, and z components of the direction vector are given by elements 0 through 2, and the components of the point on the line are given by elements 3 through 5

toString

public java.lang.String toString()
Returns a String representation of this Line3d, consisting of the components of the direction vector followed by those of the point

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 Point3d, consisting of the x, y, and z components of the direction vector, followed by components of the point. 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 Point3d, consisting of the x, y, and z components of the direction vector, followed by components of the point. 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 vector

project

public Point3d project(Point3d point)
Finds the closest point to the supplied Point3d that lies on the line.

Parameters:
point - The Point3d to project
Returns:
Point3d on the line representing the projection

epsilonContains

public boolean epsilonContains(Point3d point,
                               double eps)
Returns true if the supplied point lies on this line within a specified tolerance

Parameters:
point - Point to test if is on the line
eps - Tolerance distance
Returns:
True if point is sufficiently close to line

contains

public boolean contains(Point3d point)
Returns true if supplied point lies exactly on the line

Parameters:
point - Point3d to test
Returns:
true if point is on the line

epsilonEquals

public boolean epsilonEquals(Line3d line3d,
                             double eps)
                      throws ImproperSizeException
Returns true if the elements of this Line3d equal those of another Line3d within a prescribed tolerance epsilon.

Parameters:
line3d - Line3d to compare with
eps - comparison tolerance
Returns:
false if the Line3ds are not equal within the specified tolerance
Throws:
ImproperSizeException

equals

public boolean equals(Line3d line3d)
Returns true if the elements of this Line3d equal those of another Line3d exactly.

Parameters:
line3d - Line3d to compare with
Returns:
false if the Line3ds are not equal

equals

public boolean equals(java.lang.Object obj)
Returns true if the supplied object is a Line3d and its elements equal those of this Line3d exactly.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Object to compare with
Returns:
false if the Object does not equal this Line3d

getDirection

public void getDirection(Vector3d d)
Gets the direction vector for the line

Parameters:
d - Filled by the values of the direction vector

getPoint

public void getPoint(Vector3d p)
Gets a point on the line

Parameters:
p - Filled by values of a point on the line

setDirection

public void setDirection(Vector3d d)

setPoint

public void setPoint(Point3d p)

closestPoint

public Point3d closestPoint(Line3d line,
                            double epsilon)
Finds the point on THIS line that is closest to the supplied line

Parameters:
line - The Line3d to which we search for the closest point
epsilon - Tolerance for which lines are considered parallel
Returns:
The point on the current line which is closest to the supplied Line3d. Returns null if lines are parallel

closestPointBetweenLines

public static boolean closestPointBetweenLines(Line3d line1,
                                               Line3d line2,
                                               Point3d pnt1,
                                               Point3d pnt2,
                                               double epsilon)

closestPointBetweenLines

public static boolean closestPointBetweenLines(Vector3d v1,
                                               Point3d p1,
                                               Vector3d v2,
                                               Point3d p2,
                                               Point3d out1,
                                               Point3d out2,
                                               double epsilon)

closestPoint

public Point3d closestPoint(Line3d line)
Finds the point on THIS line that is closest to the supplied line

Parameters:
line - The Line3d to which we search for the closest point
Returns:
The point on the current line which is closest to the supplied Line3d Returns null if lines are parallel