pslib
Class PSVector

java.lang.Object
  extended by pslib.PSVector

public class PSVector
extends java.lang.Object

PSVector Class

The PSVector object specifies a location within xyz coordinate space with floating point precision.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.


Field Summary
 float x
           
 float y
           
 float z
           
 
Constructor Summary
PSVector()
          Create a new object instance with zero values
PSVector(float[] arr)
          Create a new object instance using values from the specified array
PSVector(float x, float y)
          Create a new object instance with the specified values
PSVector(float x, float y, float z)
          Create a new object instance with the specified values
PSVector(PSVector v)
          Create a new object instance using values from the specified vector
 
Method Summary
 void add(float x, float y)
          Add the specified values to this vector
 void add(float x, float y, float z)
          Add the specified values to this vector
 void add(PSVector v)
          Add the specified vector to this vector
static PSVector add(PSVector v1, PSVector v2)
          Add the two specified vectors and return the result
 float angleBetween(PSVector v)
          Return the angle between this vector and that specified
 PSVector copy()
          Return a copy of this vector
 PSVector cross(PSVector v)
          Return the cross product of this vector and that specified
 float distance(PSVector v)
          Return the distance between this vector and that specified
 float dot(PSVector v)
          Return the dot product of this vector and that specified
 PSVector getPerpendicular()
          Return a normalised vector perpendicular to this one
 void limit(float m)
          Limit this vector to the specified magnitude
static PSVector limit(PSVector v, float m)
          Limit a vector to the specified magnitude and return the result as a new vector
 float magnitude()
          Return the magnitude of this vector
 void normalise()
          Normalise this vector
static PSVector normalise(PSVector v)
          Normalise a vector and return the result as a new vector
 void normaliseTo(float m)
          Normalise this vector to the specified magnitude
static PSVector normaliseTo(PSVector v, float m)
          Normalise a vector to the specified magnitude and return the result as a new vector
 float pitch()
          Return the pitch of the vector relative to the origin in radians
 void rotateAboutOrigin(float a, PSVector av)
          Rotate this vector about the origin on the specified axis
static PSVector rotateAboutOrigin(PSVector v, float a, PSVector av)
          Rotate a vector the origin on the specified axis and return the result as a new vector
 void scale(float s)
          Multiply this vector by the specified scalar
 void scale(PSVector v)
          Multiply the component values of this vector by those within the specified vector
static PSVector scale(PSVector v, float s)
          Multiply a vector by the specified scalar and return the result as a new vector
static PSVector scale(PSVector v1, PSVector v2)
          Multiply two vectors and return the result as a new vector
 void set(float[] arr)
          Set the component values using values from the specified array
 void set(float x, float y)
          Set the x and y values
 void set(float x, float y, float z)
          Set the component values
 void set(PSVector v)
          Set the component values using values from the specified vector
 void sub(float x, float y)
          Subtract the specified values from this vector
 void sub(float x, float y, float z)
          Subtract the specified values from this vector
 void sub(PSVector v)
          Subtract the specified vector from this vector
static PSVector sub(PSVector v1, PSVector v2)
          Subtract one vector from another and return the result
 float[] toArray()
          Return the component values of this vector as an array
 java.lang.String toString()
          Return the vector component values as a string
 float yaw()
          Return the yaw of the vector relative to the origin in radians
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z
Constructor Detail

PSVector

public PSVector()
Create a new object instance with zero values


PSVector

public PSVector(float x,
                float y)
Create a new object instance with the specified values

Parameters:
x - x
y - y

PSVector

public PSVector(float x,
                float y,
                float z)
Create a new object instance with the specified values

Parameters:
x - x
y - y
z - z

PSVector

public PSVector(float[] arr)
Create a new object instance using values from the specified array

Parameters:
arr - array

PSVector

public PSVector(PSVector v)
Create a new object instance using values from the specified vector

Parameters:
v - vector
Method Detail

set

public final void set(float x,
                      float y)
Set the x and y values

Parameters:
x - x
y - y

set

public final void set(float x,
                      float y,
                      float z)
Set the component values

Parameters:
x - x
y - y
z - z

set

public final void set(float[] arr)
Set the component values using values from the specified array

Parameters:
arr - array

set

public final void set(PSVector v)
Set the component values using values from the specified vector

Parameters:
v -

copy

public PSVector copy()
Return a copy of this vector

Returns:
a copy of this vector

toArray

public final float[] toArray()
Return the component values of this vector as an array

Returns:
the component values of this vector as an array

add

public final void add(float x,
                      float y)
Add the specified values to this vector

Parameters:
x - x
y - y

add

public final void add(float x,
                      float y,
                      float z)
Add the specified values to this vector

Parameters:
x - x
y - y
z - z

add

public final void add(PSVector v)
Add the specified vector to this vector

Parameters:
v - vector

add

public static final PSVector add(PSVector v1,
                                 PSVector v2)
Add the two specified vectors and return the result

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
the result of v1 + v2

sub

public final void sub(float x,
                      float y)
Subtract the specified values from this vector

Parameters:
x - x
y - y

sub

public final void sub(float x,
                      float y,
                      float z)
Subtract the specified values from this vector

Parameters:
x - x
y - y
z - z

sub

public final void sub(PSVector v)
Subtract the specified vector from this vector

Parameters:
v - vector

sub

public static PSVector sub(PSVector v1,
                           PSVector v2)
Subtract one vector from another and return the result

Parameters:
v1 - vector 1
v2 - vector 2
Returns:
the result of v1 - v2

scale

public final void scale(float s)
Multiply this vector by the specified scalar

Parameters:
s - scalar

scale

public final void scale(PSVector v)
Multiply the component values of this vector by those within the specified vector

Parameters:
v - vector

scale

public static PSVector scale(PSVector v,
                             float s)
Multiply a vector by the specified scalar and return the result as a new vector

Parameters:
v - vector
s - scalar
Returns:
the result of v1 * s as a new vector

scale

public static PSVector scale(PSVector v1,
                             PSVector v2)
Multiply two vectors and return the result as a new vector

Parameters:
v1 -
v2 -
Returns:
the result of v1 * v2 as a new vector

limit

public final void limit(float m)
Limit this vector to the specified magnitude

Parameters:
m - magnitude

limit

public static PSVector limit(PSVector v,
                             float m)
Limit a vector to the specified magnitude and return the result as a new vector

Parameters:
v - vector
m - magnitude
Returns:
the limited result as a new vector

normalise

public final void normalise()
Normalise this vector


normalise

public static PSVector normalise(PSVector v)
Normalise a vector and return the result as a new vector

Parameters:
v - vector
Returns:
the normalised result as a new vector

normaliseTo

public final void normaliseTo(float m)
Normalise this vector to the specified magnitude

Parameters:
m - magnitude

normaliseTo

public static PSVector normaliseTo(PSVector v,
                                   float m)
Normalise a vector to the specified magnitude and return the result as a new vector

Parameters:
v - vector
m - magnitude
Returns:
the normalised result as a new vector

magnitude

public final float magnitude()
Return the magnitude of this vector

Returns:
the magnitude of this vector

distance

public final float distance(PSVector v)
Return the distance between this vector and that specified

Parameters:
v - vector
Returns:
the distance between this vector and that specified

dot

public final float dot(PSVector v)
Return the dot product of this vector and that specified

Parameters:
v - vector
Returns:
the dot product of this vector and that specified

cross

public final PSVector cross(PSVector v)
Return the cross product of this vector and that specified

Parameters:
v - vector
Returns:
the cross product of this vector and that specified

getPerpendicular

public final PSVector getPerpendicular()
Return a normalised vector perpendicular to this one

Returns:
a normalised vector perpendicular to this one

angleBetween

public final float angleBetween(PSVector v)
Return the angle between this vector and that specified

Parameters:
v - vector
Returns:
the angle between this vector and that specified

rotateAboutOrigin

public final void rotateAboutOrigin(float a,
                                    PSVector av)
Rotate this vector about the origin on the specified axis

Parameters:
a - angle
av - axis vector

rotateAboutOrigin

public static PSVector rotateAboutOrigin(PSVector v,
                                         float a,
                                         PSVector av)
Rotate a vector the origin on the specified axis and return the result as a new vector

Parameters:
v - vector to be rotated
a - angle
av - axis vector
Returns:
the result as a new vector

pitch

public final float pitch()
Return the pitch of the vector relative to the origin in radians

Returns:
the pitch of the vector relative to the origin in radians

yaw

public final float yaw()
Return the yaw of the vector relative to the origin in radians

Returns:
the yaw of the vector relative to the origin in radians

toString

public java.lang.String toString()
Return the vector component values as a string

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