org.naokishibata.math
Class Vector3D

java.lang.Object
  extended by org.naokishibata.math.Vector3D
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class Vector3D
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

Vector3D is an immutable class representing a 3-dimensional vector.

See Also:
Serialized Form

Field Summary
 double x
          The first coordinate.
 double y
          The second coordinate.
 double z
          The third coordinate.
 
Constructor Summary
Vector3D(double x0, double y0, double z0)
          Constructs a new Vector3D instance which represents (x0, y0, z0) vector.
 
Method Summary
static Vector3D add(Vector3D v, Vector3D u)
          Returns the addition of vectors v and u.
static Vector3D add(Vector3D v, Vector3D u, Vector3D w)
          Returns the addition of vectors v, u and w.
static Vector3D add(Vector3D v, Vector3D u, Vector3D w, Vector3D x)
          Returns the addition of vectors v, u, w and x.
static double angle(Vector3D v, Vector3D w)
          Returns the angle of vector v and w
static Vector3D centroid(java.lang.Iterable<? extends Vector3D> c)
          Returns the centroid of collection c of vectors
static Vector3D centroid(Vector3D v, Vector3D w)
          Returns the centroid of v and w
static Vector3D centroid(Vector3D v, Vector3D w, Vector3D x)
          Returns the centroid of v, w and x
static Vector3D centroid(Vector3D v, Vector3D w, Vector3D x, Vector3D y)
          Returns the centroid of v, w, x and y
 int compareTo(java.lang.Object o)
           
 Vector3D cross(Vector3D v)
          Returns the cross product of this and v
static Vector3D crossProduct(Vector3D v1, Vector3D v2)
          Returns the cross product of vectors v and u.
static double distance(Vector3D v, Vector3D w)
          Returns the distance between v and w
static double distanceSquared(Vector3D v, Vector3D w)
          Returns the squared distance between v and w
 Vector3D dot(double d)
          Returns this vector scaled by d
 double dot(Vector3D v)
          Returns the dot product of this and v
static double dotProduct(Vector3D v, Vector3D u)
          Returns the dot product of vectors v and u.
 boolean epsilonEquals(Vector3D v)
           
 boolean epsilonEquals(Vector3D v, double eps)
           
static boolean epsilonEquals(Vector3D v, Vector3D w)
           
static boolean epsilonEquals(Vector3D v, Vector3D w, double eps)
           
 boolean equals(java.lang.Object o)
           
 boolean equals(Vector3D v)
           
static boolean equals(Vector3D v, Vector3D w)
           
 int hashCode()
          Returns hash code of this instance
static int hashCode(Vector3D v)
           
 double length()
          Returns the length of this vector
static double length(Vector3D v)
          Returns the length of vector v
 double lengthSquared()
          Returns the squared length of this vector
static double lengthSquared(Vector3D v)
          Returns the squared length of vector v
static Vector3D midpoint(Vector3D v, Vector3D w)
          Returns the midpoint between v and w
 Vector3D minus(Vector3D v)
          Returns this - v
static Vector3D normalize(Vector3D v)
          Returns the normalized vector of v.
 Vector3D normalized()
           
 Vector3D plus(Vector3D v)
          Returns this + v
 Vector3D rotX(double rx, double bx, double by, double bz)
          Returns the vector rotated on x-axis around (bx, by, bz)
 Vector3D rotX(double r, Vector3D b)
          Returns the vector rotated on x-axis around b
static Vector3D rotX(Vector3D v, double rx, double bx, double by, double bz)
          Returns vector v rotated on x-axis around (bx, by, bz)
static Vector3D rotX(Vector3D v, double r, Vector3D b)
          Returns vector v rotated on x-axis around b
 Vector3D rotY(double rx, double bx, double by, double bz)
          Returns the vector rotated on y-axis around (bx, by, bz)
 Vector3D rotY(double r, Vector3D b)
          Returns the vector rotated on y-axis around b
static Vector3D rotY(Vector3D v, double ry, double bx, double by, double bz)
          Returns vector v rotated on y-axis around (bx, by, bz)
static Vector3D rotY(Vector3D v, double r, Vector3D b)
          Returns vector v rotated on y-axis around b
 Vector3D rotZ(double rx, double bx, double by, double bz)
          Returns the vector rotated on z-axis around (bx, by, bz)
 Vector3D rotZ(double r, Vector3D b)
          Returns the vector rotated on z-axis around b
static Vector3D rotZ(Vector3D v, double rz, double bx, double by, double bz)
          Returns vector v rotated on z-axis around (bx, by, bz)
static Vector3D rotZ(Vector3D v, double r, Vector3D b)
          Returns vector v rotated on z-axis around b
static Vector3D scale(double s, Vector3D v)
          Returns vector v scaled by s
static Vector3D scale(Vector3D v, double s)
          Returns vector v scaled by s
static Vector3D sub(Vector3D v, Vector3D u)
          Returns vector v subtracted u.
 Vector3D times(double d)
          Returns this vector scaled by d
 float[] toFloatArray()
          Convert this vector to a float array
 float[] toFloatArray(int n)
          Convert this vector to a float array of length n
 java.lang.String toString()
          Returns the string representation of the vector.
 double x()
          Returns the first coordinate of the vector.
 double y()
          Returns the second coordinate of the vector.
 double z()
          Returns the third coordinate of the vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public final double x
The first coordinate.


y

public final double y
The second coordinate.


z

public final double z
The third coordinate.

Constructor Detail

Vector3D

public Vector3D(double x0,
                double y0,
                double z0)
Constructs a new Vector3D instance which represents (x0, y0, z0) vector.

Method Detail

x

public double x()
Returns the first coordinate of the vector.


y

public double y()
Returns the second coordinate of the vector.


z

public double z()
Returns the third coordinate of the vector.


toString

public java.lang.String toString()
Returns the string representation of the vector.

Overrides:
toString in class java.lang.Object

add

public static Vector3D add(Vector3D v,
                           Vector3D u)
Returns the addition of vectors v and u.


add

public static Vector3D add(Vector3D v,
                           Vector3D u,
                           Vector3D w)
Returns the addition of vectors v, u and w.


add

public static Vector3D add(Vector3D v,
                           Vector3D u,
                           Vector3D w,
                           Vector3D x)
Returns the addition of vectors v, u, w and x.


sub

public static Vector3D sub(Vector3D v,
                           Vector3D u)
Returns vector v subtracted u.


dotProduct

public static double dotProduct(Vector3D v,
                                Vector3D u)
Returns the dot product of vectors v and u.


crossProduct

public static Vector3D crossProduct(Vector3D v1,
                                    Vector3D v2)
Returns the cross product of vectors v and u.


scale

public static Vector3D scale(double s,
                             Vector3D v)
Returns vector v scaled by s


scale

public static Vector3D scale(Vector3D v,
                             double s)
Returns vector v scaled by s


normalize

public static Vector3D normalize(Vector3D v)
Returns the normalized vector of v.


length

public static double length(Vector3D v)
Returns the length of vector v


lengthSquared

public static double lengthSquared(Vector3D v)
Returns the squared length of vector v


distance

public static double distance(Vector3D v,
                              Vector3D w)
Returns the distance between v and w


distanceSquared

public static double distanceSquared(Vector3D v,
                                     Vector3D w)
Returns the squared distance between v and w


midpoint

public static Vector3D midpoint(Vector3D v,
                                Vector3D w)
Returns the midpoint between v and w


centroid

public static Vector3D centroid(Vector3D v,
                                Vector3D w)
Returns the centroid of v and w


centroid

public static Vector3D centroid(Vector3D v,
                                Vector3D w,
                                Vector3D x)
Returns the centroid of v, w and x


centroid

public static Vector3D centroid(Vector3D v,
                                Vector3D w,
                                Vector3D x,
                                Vector3D y)
Returns the centroid of v, w, x and y


angle

public static double angle(Vector3D v,
                           Vector3D w)
Returns the angle of vector v and w


rotX

public static Vector3D rotX(Vector3D v,
                            double rx,
                            double bx,
                            double by,
                            double bz)
Returns vector v rotated on x-axis around (bx, by, bz)


rotY

public static Vector3D rotY(Vector3D v,
                            double ry,
                            double bx,
                            double by,
                            double bz)
Returns vector v rotated on y-axis around (bx, by, bz)


rotZ

public static Vector3D rotZ(Vector3D v,
                            double rz,
                            double bx,
                            double by,
                            double bz)
Returns vector v rotated on z-axis around (bx, by, bz)


rotX

public static Vector3D rotX(Vector3D v,
                            double r,
                            Vector3D b)
Returns vector v rotated on x-axis around b


rotY

public static Vector3D rotY(Vector3D v,
                            double r,
                            Vector3D b)
Returns vector v rotated on y-axis around b


rotZ

public static Vector3D rotZ(Vector3D v,
                            double r,
                            Vector3D b)
Returns vector v rotated on z-axis around b


rotX

public Vector3D rotX(double rx,
                     double bx,
                     double by,
                     double bz)
Returns the vector rotated on x-axis around (bx, by, bz)


rotY

public Vector3D rotY(double rx,
                     double bx,
                     double by,
                     double bz)
Returns the vector rotated on y-axis around (bx, by, bz)


rotZ

public Vector3D rotZ(double rx,
                     double bx,
                     double by,
                     double bz)
Returns the vector rotated on z-axis around (bx, by, bz)


rotX

public Vector3D rotX(double r,
                     Vector3D b)
Returns the vector rotated on x-axis around b


rotY

public Vector3D rotY(double r,
                     Vector3D b)
Returns the vector rotated on y-axis around b


rotZ

public Vector3D rotZ(double r,
                     Vector3D b)
Returns the vector rotated on z-axis around b


epsilonEquals

public static boolean epsilonEquals(Vector3D v,
                                    Vector3D w,
                                    double eps)

epsilonEquals

public static boolean epsilonEquals(Vector3D v,
                                    Vector3D w)

length

public double length()
Returns the length of this vector


lengthSquared

public double lengthSquared()
Returns the squared length of this vector


epsilonEquals

public boolean epsilonEquals(Vector3D v,
                             double eps)

epsilonEquals

public boolean epsilonEquals(Vector3D v)

plus

public Vector3D plus(Vector3D v)
Returns this + v


minus

public Vector3D minus(Vector3D v)
Returns this - v


normalized

public Vector3D normalized()

dot

public double dot(Vector3D v)
Returns the dot product of this and v


dot

public Vector3D dot(double d)
Returns this vector scaled by d


times

public Vector3D times(double d)
Returns this vector scaled by d


cross

public Vector3D cross(Vector3D v)
Returns the cross product of this and v


hashCode

public int hashCode()
Returns hash code of this instance

Overrides:
hashCode in class java.lang.Object

hashCode

public static int hashCode(Vector3D v)

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(Vector3D v)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

equals

public static boolean equals(Vector3D v,
                             Vector3D w)

centroid

public static Vector3D centroid(java.lang.Iterable<? extends Vector3D> c)
Returns the centroid of collection c of vectors


toFloatArray

public float[] toFloatArray()
Convert this vector to a float array


toFloatArray

public float[] toFloatArray(int n)
Convert this vector to a float array of length n