za.co.luma.geom
Class Vector3DDouble

java.lang.Object
  extended by za.co.luma.geom.Vector3DDouble

public class Vector3DDouble
extends java.lang.Object

Class that represents a real 3D vector.

Author:
Herman Tulleken

Field Summary
 double x
           
 double y
           
 double z
           
 
Constructor Summary
Vector3DDouble(double x, double y, double z)
          Constructs a new vector with the given coordinates.
 
Method Summary
static Vector3DDouble add(Vector3DDouble p1, Vector3DDouble p2)
          Adds two vectors, and return the result.
static double distance(Vector3DDouble p1, Vector3DDouble p2)
          Returns the Euclidean distance between two points.
static double getHeight(double x, double y, Vector3DDouble p, Vector3DDouble q)
          Returns a z-coordinate so that the vector (x, y, z) lies in the same plane as the plane which contains both p and q.
static Vector3DDouble getPointBetween(Vector3DDouble p1, Vector3DDouble p2, double r)
          Gets a point between two points.
 double getX()
           
 double getY()
           
 double getZ()
           
static boolean pointInTriangle(Vector3DDouble p, Vector3DDouble a, Vector3DDouble b, Vector3DDouble c)
          Checks whether a point lies within the triangle described by three vertices.
static boolean sameSide(Vector3DDouble p1, Vector3DDouble p2, Vector3DDouble a, Vector3DDouble b)
          Checks whether a and b lies on the same side of line p1-p2, or not.
static double scalarCross(Vector3DDouble p1, Vector3DDouble p2)
          Returns the z-coordinate of the cross product of two points projected on the plane z = 0, (embedded in 3D space).
 void scale(double r)
          Scale this vector by a given factor.
static Vector3DDouble scale(Vector3DDouble p, double r)
          Returns a new vector, in the same direction as p, but sacled by a factor r.
 void setLocation(double x, double y, double z)
          Sets the new coordinates for this vector.
 double size()
          Returns the size (Euclidean length) of this vector.
static double size(Vector3DDouble p)
          Returns the Euclidean length of this vector.
static Vector3DDouble subtract(Vector3DDouble p1, Vector3DDouble p2)
          Subtracts p2 from p1 and returns the result as a new vector.
 java.lang.String toString()
           
static Vector3DDouble unit(Vector3DDouble p1)
          Returns a new unit vector in the same direcction as the given vector.
 Vector3DDouble unitVector()
          Returns a unit length vector in the same direction is this vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x

y

public double y

z

public double z
Constructor Detail

Vector3DDouble

public Vector3DDouble(double x,
                      double y,
                      double z)
Constructs a new vector with the given coordinates.

Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate
Method Detail

getX

public double getX()
Returns:
The x-coordinate

getY

public double getY()
Returns:
The y-coordinate

getZ

public double getZ()
Returns:
The z-coordinate

setLocation

public void setLocation(double x,
                        double y,
                        double z)
Sets the new coordinates for this vector.

Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

size

public double size()
Returns the size (Euclidean length) of this vector.

Returns:
A non-negative real number denoting the length of this vector.

scale

public void scale(double r)
Scale this vector by a given factor.

Parameters:
r - The scaling factor.

unitVector

public Vector3DDouble unitVector()
Returns a unit length vector in the same direction is this vector.

Returns:
A new vector of unit length, pointing in the same direction as this vector.

distance

public static double distance(Vector3DDouble p1,
                              Vector3DDouble p2)
Returns the Euclidean distance between two points.

Returns:

scalarCross

public static double scalarCross(Vector3DDouble p1,
                                 Vector3DDouble p2)
Returns the z-coordinate of the cross product of two points projected on the plane z = 0, (embedded in 3D space).


sameSide

public static boolean sameSide(Vector3DDouble p1,
                               Vector3DDouble p2,
                               Vector3DDouble a,
                               Vector3DDouble b)
Checks whether a and b lies on the same side of line p1-p2, or not. If either or both points lie on the line, the method returns true.


pointInTriangle

public static boolean pointInTriangle(Vector3DDouble p,
                                      Vector3DDouble a,
                                      Vector3DDouble b,
                                      Vector3DDouble c)
Checks whether a point lies within the triangle described by three vertices.

Parameters:
p - The point.
a - One vertice of the triangle.
b - One vertice of the triangle.
c - One vertice of the triangle.
Returns:
True if the point lies within the triangle, false otherwise.

add

public static Vector3DDouble add(Vector3DDouble p1,
                                 Vector3DDouble p2)
Adds two vectors, and return the result.

Returns:
A new vector, the sum of the parameters.

getPointBetween

public static Vector3DDouble getPointBetween(Vector3DDouble p1,
                                             Vector3DDouble p2,
                                             double r)
Gets a point between two points. More correct, returns a new vector laying in the same line as p2 - p1.

Parameters:
p1 -
p2 -
r - Controls the distance of the new point from the other points. If r is 0, the new point coincides with p1, if r is 1, the new point coincides with p2. If r lies between 0, and 1, the new point lies between p1 and p2. If r is smaller than 0, p1 lies between the new point and p2, and if r is greater than 1, p2 lies between the new point and p1.
Returns:
A new vector

scale

public static Vector3DDouble scale(Vector3DDouble p,
                                   double r)
Returns a new vector, in the same direction as p, but sacled by a factor r.

Parameters:
p - Direction and original size.
r - Scaling fator
Returns:
A new vector, a factor of p1.

size

public static double size(Vector3DDouble p)
Returns the Euclidean length of this vector.

Parameters:
p -
Returns:

subtract

public static Vector3DDouble subtract(Vector3DDouble p1,
                                      Vector3DDouble p2)
Subtracts p2 from p1 and returns the result as a new vector.


unit

public static Vector3DDouble unit(Vector3DDouble p1)
Returns a new unit vector in the same direcction as the given vector.


getHeight

public static double getHeight(double x,
                               double y,
                               Vector3DDouble p,
                               Vector3DDouble q)
Returns a z-coordinate so that the vector (x, y, z) lies in the same plane as the plane which contains both p and q.