mr3d.lang
Class Vector3D

java.lang.Object
  extended bymr3d.lang.Vector3D
All Implemented Interfaces:
Debugable

public class Vector3D
extends java.lang.Object
implements Debugable

The class Vector3D is able to represent a homogeneous vector.

Since:
MR3Dv1.0
Version:
10-2004
Author:
Manuel Ruelke

Field Summary
 int h
          homogeneous coordinate of the vector
 int x
          x-coordinate of the vector
 int y
          y-coordinate of the vector
 int z
          z-coordinate of the vector
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
Vector3D()
          Creates a vector with all components set to 0.
Vector3D(int newX, int newY, int newZ, int newH)
          Creates a vector using the specified values.
 
Method Summary
 Vector3D add(Vector3D addVec)
          Adds this the components of this vector to the compontens of the specified one and returns the result vector.
 Vector3D clone()
          Returns a copy of this vector.
 Vector3D cross(Vector3D crossVector)
          Calculates the cross product of this vector with a specified one.
 Vector3D div(int divider)
          Divides a the vector by a specified number.
 int dot(Vector3D aVector)
          Calculates the scalar product of two vectors.
 boolean equals(Vector3D otherVector)
          Compares this vector with a another specified one and return the result of the test.
 boolean isEmpty()
          Returns the result of the test if the vector components exept h are 0.
 Vector3D mul(int factor)
          Multiplies the vector all components with a specified factor.
 void resetTozero()
          Resets the vector components to zero.
 void selfDiv(int divider)
          Devides this vector by a specified number and stores the result in this vector.
 void selfMul(int factor)
          Multiplies this vector with a specified factor and stores the result in this vector.
 void set(int newX, int newY, int newZ, int newH)
          Sets the vector components according to the specified parameters.
 Vector3D sub(Vector3D subVec)
          Subtracts a vector from this vector and returns the result.
 void toConsole()
          Prints the contents of the object to the Java console.
 void toConsole(java.lang.String msgString)
          Prints the contents of the object to the Java console together with an information string.
 int velocity()
          Returns the velocity of the vector.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

h

public int h
homogeneous coordinate of the vector


x

public int x
x-coordinate of the vector


y

public int y
y-coordinate of the vector


z

public int z
z-coordinate of the vector

Constructor Detail

Vector3D

public Vector3D()
Creates a vector with all components set to 0.


Vector3D

public Vector3D(int newX,
                int newY,
                int newZ,
                int newH)
Creates a vector using the specified values.

Parameters:
newX - x-coordinate of the vector
newY - y-coordinate of the vector
newZ - z-coordinate of the vector
newH - homogeneous coordinate of the vector
Method Detail

add

public Vector3D add(Vector3D addVec)
Adds this the components of this vector to the compontens of the specified one and returns the result vector. All components are added but the homogeneous component.

Parameters:
addVec - the vector that will be added to this vector
Returns:
the result of the vector addition

clone

public Vector3D clone()
Returns a copy of this vector.

Returns:
copy of this vector

cross

public Vector3D cross(Vector3D crossVector)
Calculates the cross product of this vector with a specified one. The method returns the result of the operation in the result vector.

Example The mathematical expression

crossProd = Vector1 x Vector2

can be realized with

Vector3D crossProd = Vector1.cross(Vector2);

Parameters:
crossVector - the vector to be
Returns:
the cross product vector

div

public Vector3D div(int divider)
Divides a the vector by a specified number. All components are devided by this number. The only exception is the component h. It will not be divided.

Parameters:
divider - number by which the vector components are devided
Returns:
the result vector of the devision

dot

public int dot(Vector3D aVector)
Calculates the scalar product of two vectors.

Parameters:
aVector - the other vector of which the scalar product is calculated from
Returns:
the result of the scalar product of this vector and the specified one

equals

public boolean equals(Vector3D otherVector)
Compares this vector with a another specified one and return the result of the test.


isEmpty

public boolean isEmpty()
Returns the result of the test if the vector components exept h are 0.

Returns:
"true" if empty, "false" if vector contains conponents different from 0

mul

public Vector3D mul(int factor)
Multiplies the vector all components with a specified factor. The only exception is the component h. It will not be multiplied.

Parameters:
factor - is multiplied with the vector elements
Returns:
the result vector

resetTozero

public void resetTozero()
Resets the vector components to zero.


selfDiv

public void selfDiv(int divider)
Devides this vector by a specified number and stores the result in this vector. All components are devided but the homogeneous element.

Parameters:
divider - number by which the vector components are devided

selfMul

public void selfMul(int factor)
Multiplies this vector with a specified factor and stores the result in this vector. All components are multiplied multiplied but the homogeneous element.

Parameters:
factor - is multiplied with the vector elements

set

public void set(int newX,
                int newY,
                int newZ,
                int newH)
Sets the vector components according to the specified parameters.


sub

public Vector3D sub(Vector3D subVec)
Subtracts a vector from this vector and returns the result. All components are subtracted but the homogeneous component.

Parameters:
subVec - the vector that will be added to this vector
Returns:
the result of the vector addition

toConsole

public void toConsole()
Description copied from interface: Debugable
Prints the contents of the object to the Java console. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

toConsole

public void toConsole(java.lang.String msgString)
Description copied from interface: Debugable
Prints the contents of the object to the Java console together with an information string. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

velocity

public int velocity()
Returns the velocity of the vector. The velocity is calculates by

SQRT(x^2 + y^2 + z^2);

Returns:
velocity