paulscode.sound
Class Vector3D

java.lang.Object
  extended by paulscode.sound.Vector3D

public class Vector3D
extends java.lang.Object

The Vector3D class contains methods to simplify common 3D vector functions, such as cross and dot product, normalize, etc.

SoundSystem License:

You are free to use this library for any purpose, commercial or otherwise. You may modify this library or source code, and distribute it any way you like, provided the following conditions are met:
1) You may not falsely claim to be the author of this library or any unmodified portion of it.
2) You may not copyright this library or a modified version of it and then sue me for copyright infringement.
3) If you modify the source code, you must clearly document the changes made before redistributing the modified source code, so other users know it is not the original code.
4) You are not required to give me credit for this library in any derived work, but if you do, you must also mention my website: http://www.paulscode.com
5) I the author will not be responsible for any damages (physical, financial, or otherwise) caused by the use if this library or any part of it.
6) I the author do not guarantee, warrant, or make any representations, either expressed or implied, regarding the use of this library or any part of it.

Author: Paul Lamb
http://www.paulscode.com


Field Summary
 float x
          The vector's X coordinate.
 float y
          The vector's Y coordinate.
 float z
          The vector's Z coordinate.
 
Constructor Summary
Vector3D()
          Constructor: Places the vector at the origin.
Vector3D(float nx, float ny, float nz)
          Constructor: Places the vector at the specified 3D coordinates.
 
Method Summary
 Vector3D add(Vector3D B)
          Returns the vector represented by: (this) + B.
 Vector3D add(Vector3D A, Vector3D B)
          Returns the vector represented by: A + B.
 Vector3D clone()
          Returns a new instance containing the same information as this one.
 Vector3D cross(Vector3D B)
          Returns a vector containing the cross-product: (this) cross B.
 Vector3D cross(Vector3D A, Vector3D B)
          Returns a vector containing the cross-product: A cross B.
 float dot(Vector3D B)
          Returns the dot-product result of: (this) dot B.
 float dot(Vector3D A, Vector3D B)
          Returns the dot-product result of: A dot B.
 float length()
          Returns the length of this vector.
 void normalize()
          Changes the length of this vector to 1.0.
 Vector3D subtract(Vector3D B)
          Returns the vector represented by: (this) - B.
 Vector3D subtract(Vector3D A, Vector3D B)
          Returns the vector represented by: A - B.
 java.lang.String toString()
          Returns a string depicting this vector.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x
The vector's X coordinate.


y

public float y
The vector's Y coordinate.


z

public float z
The vector's Z coordinate.

Constructor Detail

Vector3D

public Vector3D()
Constructor: Places the vector at the origin.


Vector3D

public Vector3D(float nx,
                float ny,
                float nz)
Constructor: Places the vector at the specified 3D coordinates.

Parameters:
nx - X coordinate for the new vector.
ny - Y coordinate for the new vector.
nz - Z coordinate for the new vector.
Method Detail

clone

public Vector3D clone()
Returns a new instance containing the same information as this one.

Overrides:
clone in class java.lang.Object
Returns:
A new Vector3D.

cross

public Vector3D cross(Vector3D A,
                      Vector3D B)
Returns a vector containing the cross-product: A cross B.

Parameters:
A - First vector in the cross product.
B - Second vector in the cross product.
Returns:
A new Vector3D.

cross

public Vector3D cross(Vector3D B)
Returns a vector containing the cross-product: (this) cross B.

Parameters:
B - Second vector in the cross product.
Returns:
A new Vector3D.

dot

public float dot(Vector3D A,
                 Vector3D B)
Returns the dot-product result of: A dot B.

Parameters:
A - First vector in the dot product.
B - Second vector in the dot product.
Returns:
Dot product.

dot

public float dot(Vector3D B)
Returns the dot-product result of: (this) dot B.

Parameters:
B - Second vector in the dot product.
Returns:
Dot product.

add

public Vector3D add(Vector3D A,
                    Vector3D B)
Returns the vector represented by: A + B.

Parameters:
A - First vector.
B - Vector to add to A.
Returns:
A new Vector3D.

add

public Vector3D add(Vector3D B)
Returns the vector represented by: (this) + B.

Parameters:
B - Vector to add to this one.
Returns:
A new Vector3D.

subtract

public Vector3D subtract(Vector3D A,
                         Vector3D B)
Returns the vector represented by: A - B.

Parameters:
A - First vector.
B - Vector to subtract from A.
Returns:
A new Vector3D.

subtract

public Vector3D subtract(Vector3D B)
Returns the vector represented by: (this) - B.

Parameters:
B - Vector to subtract from this one.
Returns:
A new Vector3D.

length

public float length()
Returns the length of this vector.

Returns:
Length.

normalize

public void normalize()
Changes the length of this vector to 1.0.


toString

public java.lang.String toString()
Returns a string depicting this vector.

Overrides:
toString in class java.lang.Object
Returns:
"Vector3D (x, y, z)".