quickhull3d
Class Vector3d

java.lang.Object
  extended by quickhull3d.Vector3d
Direct Known Subclasses:
Point3d

public class Vector3d
extends java.lang.Object

A three-element vector. This class is actually a reduced version of the Vector3d class contained in the author's matlib package (which was partly inspired by javax.vecmath). Only a mininal number of methods which are relevant to convex hull generation are supplied here.

Author:
John E. Lloyd, Fall 2004

Field Summary
 double x
          First element
 double y
          Second element
 double z
          Third element
 
Constructor Summary
Vector3d()
          Creates a 3-vector and initializes its elements to 0.
Vector3d(double x, double y, double z)
          Creates a 3-vector with the supplied element values.
Vector3d(Vector3d v)
          Creates a 3-vector by copying an existing one.
 
Method Summary
 void add(Vector3d v1)
          Adds this vector to v1 and places the result in this vector.
 void add(Vector3d v1, Vector3d v2)
          Adds vector v1 to v2 and places the result in this vector.
 void cross(Vector3d v1, Vector3d v2)
          Computes the cross product of v1 and v2 and places the result in this vector.
 double distance(Vector3d v)
          Returns the Euclidean distance between this vector and vector v.
 double distanceSquared(Vector3d v)
          Returns the squared of the Euclidean distance between this vector and vector v.
 double dot(Vector3d v1)
          Returns the dot product of this vector and v1.
 double get(int i)
          Gets a single element of this vector.
 double norm()
          Returns the 2 norm of this vector.
 void normalize()
          Normalizes this vector in place.
 double normSquared()
          Returns the square of the 2 norm of this vector.
 void scale(double s)
          Scales the elements of this vector by s.
 void scale(double s, Vector3d v1)
          Scales the elements of vector v1 by s and places the results in this vector.
 void set(double x, double y, double z)
          Sets the elements of this vector to the prescribed values.
 void set(int i, double value)
          Sets a single element of this vector.
 void set(Vector3d v1)
          Sets the values of this vector to those of v1.
 void setZero()
          Sets the elements of this vector to zero.
 void sub(Vector3d v1)
          Subtracts v1 from this vector and places the result in this vector.
 void sub(Vector3d v1, Vector3d v2)
          Subtracts vector v1 from v2 and places the result in this vector.
 java.lang.String toString()
          Returns a string representation of this vector, consisting of the x, y, and z coordinates.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
First element


y

public double y
Second element


z

public double z
Third element

Constructor Detail

Vector3d

public Vector3d()
Creates a 3-vector and initializes its elements to 0.


Vector3d

public Vector3d(Vector3d v)
Creates a 3-vector by copying an existing one.

Parameters:
v - vector to be copied

Vector3d

public Vector3d(double x,
                double y,
                double z)
Creates a 3-vector with the supplied element values.

Parameters:
x - first element
y - second element
z - third element
Method Detail

get

public double get(int i)
Gets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.

Parameters:
i - element index
Returns:
element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.

set

public void set(int i,
                double value)
Sets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.

Parameters:
i - element index
value - element value

set

public void set(Vector3d v1)
Sets the values of this vector to those of v1.

Parameters:
v1 - vector whose values are copied

add

public void add(Vector3d v1,
                Vector3d v2)
Adds vector v1 to v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
v2 - right-hand vector

add

public void add(Vector3d v1)
Adds this vector to v1 and places the result in this vector.

Parameters:
v1 - right-hand vector

sub

public void sub(Vector3d v1,
                Vector3d v2)
Subtracts vector v1 from v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
v2 - right-hand vector

sub

public void sub(Vector3d v1)
Subtracts v1 from this vector and places the result in this vector.

Parameters:
v1 - right-hand vector

scale

public void scale(double s)
Scales the elements of this vector by s.

Parameters:
s - scaling factor

scale

public void scale(double s,
                  Vector3d v1)
Scales the elements of vector v1 by s and places the results in this vector.

Parameters:
s - scaling factor
v1 - vector to be scaled

norm

public double norm()
Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.

Returns:
vector 2 norm

normSquared

public double normSquared()
Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.

Returns:
square of the 2 norm

distance

public double distance(Vector3d v)
Returns the Euclidean distance between this vector and vector v.

Returns:
distance between this vector and v

distanceSquared

public double distanceSquared(Vector3d v)
Returns the squared of the Euclidean distance between this vector and vector v.

Returns:
squared distance between this vector and v

dot

public double dot(Vector3d v1)
Returns the dot product of this vector and v1.

Parameters:
v1 - right-hand vector
Returns:
dot product

normalize

public void normalize()
Normalizes this vector in place.


setZero

public void setZero()
Sets the elements of this vector to zero.


set

public void set(double x,
                double y,
                double z)
Sets the elements of this vector to the prescribed values.

Parameters:
x - value for first element
y - value for second element
z - value for third element

cross

public void cross(Vector3d v1,
                  Vector3d v2)
Computes the cross product of v1 and v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
v2 - right-hand vector

toString

public java.lang.String toString()
Returns a string representation of this vector, consisting of the x, y, and z coordinates.

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