ssmith.opengl
Class Vector3D

java.lang.Object
  extended by ssmith.opengl.Vector3D

public class Vector3D
extends java.lang.Object

This class can represent a 3D vector. For instance a point in 3D space, or a relative position or movement. The class has methods to add, subtact, (cross and dot) multiply with other vectors. also many other methods.


Field Summary
static boolean saveAsDouble
          VRML only supports float but allow override if higher resolution required
 double x
          x coordinate
 double y
          y coordinate
 double z
          z coordinate
 
Constructor Summary
Vector3D()
          construct a vector with initial value zero.
Vector3D(double x1, double y1, double z1)
          a constructor to set initial values of x,y and z coodinates
Vector3D(float x1, float y1, float z1)
          a constructor to set initial values of x,y and z coodinates
Vector3D(Vector3D in1)
          copy constructor
 
Method Summary
 void add(Vector3D other)
          add other vector to this for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm
static Vector3D add(Vector3D a, Vector3D b)
          static method to return sum of two vectors
 void bounds(Vector3D other, int i)
          use to combine bounds if i=0 take minimum otherwise maximum
 java.lang.Object clone()
          overrides base clone method
 void copy(Vector3D other)
          set the value of this instance to the value of other this can be used to reuse an instance without the overheads of garbidge collection
 void cross(Vector3D other)
          cross product for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm
 double distanceSquared(Vector3D other)
          return square of distance from end of this vector to end of other
 double dot(Vector3D other)
          dot product for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm
 boolean equals(Vector3D other)
          returns true if this vector has an equal value to other vector
 Vector3D getMinus()
          return a vector pointing on the opposite direction to this without affecting the value of this instance
 double getx()
          gets the value in the x dimension
 double gety()
          gets the value in the y dimension
 double getz()
          gets the value in the z dimension
 boolean greaterThan(Vector3D other)
          returns true if any dimension of other vector is greater than the same dimension of this
 boolean lessThan(Vector3D other)
          returns true if any dimension of other vector is less than the same dimension of this
 void minus()
          inverts the direction of the vector
 void normalize()
          convert this vector to unit length for theory see: http://www.euclideanspace.com/maths/algebra/vectors/normals/index.htm
 java.lang.String outstring(int format)
          output as a string
 void scale(double sc)
          scale this vector equally in all directions
 void scale(Vector3D other)
          scale this vector posibly different in x,y and z directions
 void scaleInv(Vector3D other)
          scale this vector by inverse of other
 void setX(double v)
          set the x value only without althering the other dimentions
 void setY(double v)
          set the y value only without althering the other dimentions
 void setZ(double v)
          set the z value only without althering the other dimentions
 void sub(Vector3D other)
          subtract other vector from this for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm
static Vector3D sub(Vector3D a, Vector3D b)
          static method to return difference of two vectors
 java.lang.String toStatic()
          return a string which represents the value which can be used in source code
static java.lang.String vrmlType_s()
          static method to give the VRML name of this vector
 java.lang.String vrmlType()
          method to give the VRML name of this vector sometimes we cant use vrmlType_s because static methods cant be overriden
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

saveAsDouble

public static boolean saveAsDouble
VRML only supports float but allow override if higher resolution required


x

public double x
x coordinate


y

public double y
y coordinate


z

public double z
z coordinate

Constructor Detail

Vector3D

public Vector3D(double x1,
                double y1,
                double z1)
a constructor to set initial values of x,y and z coodinates

Parameters:
x1 - value of x coordinate
y1 - value of y coordinate
z1 - value of z coordinate

Vector3D

public Vector3D(float x1,
                float y1,
                float z1)
a constructor to set initial values of x,y and z coodinates

Parameters:
x1 - value of x coordinate
y1 - value of y coordinate
z1 - value of z coordinate

Vector3D

public Vector3D(Vector3D in1)
copy constructor

Parameters:
in1 - set values to save value in1 returns a new instace with values the same as in1

Vector3D

public Vector3D()
construct a vector with initial value zero.

Method Detail

add

public static Vector3D add(Vector3D a,
                           Vector3D b)
static method to return sum of two vectors

Parameters:
a - first vector to be added
b - second vector to be added
Returns:
the sum

sub

public static Vector3D sub(Vector3D a,
                           Vector3D b)
static method to return difference of two vectors

Parameters:
a - first vector
b - subract this vector
Returns:
result

vrmlType_s

public static java.lang.String vrmlType_s()
static method to give the VRML name of this vector


vrmlType

public java.lang.String vrmlType()
method to give the VRML name of this vector sometimes we cant use vrmlType_s because static methods cant be overriden


clone

public java.lang.Object clone()
overrides base clone method

Overrides:
clone in class java.lang.Object
Returns:
new instance with same value of this

copy

public void copy(Vector3D other)
set the value of this instance to the value of other this can be used to reuse an instance without the overheads of garbidge collection

Parameters:
other - instace we want to use value of, if null then set to zero

sub

public void sub(Vector3D other)
subtract other vector from this for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm

Parameters:
other - vector to be subtracted from this

add

public void add(Vector3D other)
add other vector to this for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm

Parameters:
other - vector to be added to this

minus

public void minus()
inverts the direction of the vector


getMinus

public Vector3D getMinus()
return a vector pointing on the opposite direction to this without affecting the value of this instance

Returns:
new instance with value= munus this

normalize

public void normalize()
convert this vector to unit length for theory see: http://www.euclideanspace.com/maths/algebra/vectors/normals/index.htm


scale

public void scale(double sc)
scale this vector equally in all directions

Parameters:
sc - scale factor

scale

public void scale(Vector3D other)
scale this vector posibly different in x,y and z directions

Parameters:
other - scale value

scaleInv

public void scaleInv(Vector3D other)
scale this vector by inverse of other

Parameters:
other - scale value

distanceSquared

public double distanceSquared(Vector3D other)
return square of distance from end of this vector to end of other

Parameters:
other - calcules distance from this vector
Returns:
square of distance from end of this vector to end of other

cross

public void cross(Vector3D other)
cross product for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm

Parameters:
other - vector to take cross product with

dot

public double dot(Vector3D other)
dot product for theory see: http://www.euclideanspace.com/maths/algebra/vectors/index.htm

Parameters:
other - vector to take dot product with
Returns:
dot product

setX

public void setX(double v)
set the x value only without althering the other dimentions

Parameters:
v - new value for x

setY

public void setY(double v)
set the y value only without althering the other dimentions

Parameters:
v - new value for y

setZ

public void setZ(double v)
set the z value only without althering the other dimentions

Parameters:
v - new value for z

getx

public double getx()
gets the value in the x dimension

Returns:
the value in the x dimension

gety

public double gety()
gets the value in the y dimension

Returns:
the value in the y dimension

getz

public double getz()
gets the value in the z dimension

Returns:
the value in the z dimension

toStatic

public java.lang.String toStatic()
return a string which represents the value which can be used in source code

Returns:
a string representing the value of this

greaterThan

public boolean greaterThan(Vector3D other)
returns true if any dimension of other vector is greater than the same dimension of this

Parameters:
other - vector to compare with this
Returns:
true if greater

lessThan

public boolean lessThan(Vector3D other)
returns true if any dimension of other vector is less than the same dimension of this

Parameters:
other - vector to compare with this
Returns:
true if less

equals

public boolean equals(Vector3D other)
returns true if this vector has an equal value to other vector

Parameters:
other - vector to compare with this
Returns:

outstring

public java.lang.String outstring(int format)
output as a string

Parameters:
format">mode - values 0 - output modified values 1 - output original values 2 - output attribute 3 - output attribute in brackets 4 - output with f prefix
Returns:
string result

bounds

public void bounds(Vector3D other,
                   int i)
use to combine bounds if i=0 take minimum otherwise maximum

Parameters:
other">vector - to combine with
i">if - i=0 take minimum otherwise maximum