org.instantreality.InstantIO
Class Vec4d

java.lang.Object
  extended by org.instantreality.InstantIO.Vec4d

public class Vec4d
extends java.lang.Object

Helper class for exchanging vectors of four double components.

Vec4d is a basic helper class for exchanging vectors of four double components between different software components. It does not contain any means for vector arithmetics, only methods for setting and getting the components. It is not meant to be used directly by software components for vector representation. Instead, software components should use their own, appropriate classes for handling vectors. Only when sending vectors to an OutSlot, or when receiving vectors from an InSlot, the internal representation of vectors should be converted to Vec4d's. This ensures the interoperability between different software components that use different internal representations for vectors.

The following example creates a Vec4d object and prints its components to the console:

 Vec4d vec = new Vec4d(1.0, 2.0, 3.0, 4.0);
 System.out.println("x component = " + vec.getX());
 System.out.println("y component = " + vec.getY());
 System.out.println("z component = " + vec.getZ());
 System.out.println("w component = " + vec.getW());
 

Author:
Patrick Dähne

Field Summary
static Vec4d NULL
          The null vector <0,0,0,0>.
 
Constructor Summary
Vec4d(double[] vec)
          Constructor that initializes the components of the Vec4d object with the values of a given double array.
Vec4d(double x, double y, double z, double w)
          Constructor that initializes the components of the Vec4d object with the given double values.
Vec4d(Vec4d vec)
          Constructor that initializes the components of the Vec4d object with the components taken from another Vec4d object.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares the vector to another object.
 void get(double[] vec)
          Returns the values of the x, y, z and w components.
 double getW()
          Returns the value of the w component.
 double getX()
          Returns the value of the x component.
 double getY()
          Returns the value of the y component.
 double getZ()
          Returns the value of the z component.
 java.lang.String toString()
          Converts the vector to a string.
static Vec4d valueOf(java.lang.String str)
          Converts a string to a Vec4d object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final Vec4d NULL
The null vector <0,0,0,0>.

Constructor Detail

Vec4d

public Vec4d(double x,
             double y,
             double z,
             double w)
Constructor that initializes the components of the Vec4d object with the given double values.

The following example demonstrates how to create a Vec4d object:

 double x_component = 1.0;
 double y_component = 2.0;
 double z_component = 3.0;
 double w_component = 4.0;
 Vec4d vec = new Vec4d(x_component, y_component, z_component, w_component);
 

Parameters:
x - Value of the x component of the new vector.
y - Value of the y component of the new vector.
z - Value of the z component of the new vector.
w - Value of the w component of the new vector.

Vec4d

public Vec4d(double[] vec)
Constructor that initializes the components of the Vec4d object with the values of a given double array.

The following example demonstrates how to create a Vec4d object:

 double x_component = 1.0;
 double y_component = 2.0;
 double z_component = 3.0;
 double w_component = 4.0;
 double[] vector_components = new double[] { x_component, y_component, z_component, w_component };
 Vec4d vec = new Vec4d(vector_components);
 

Parameters:
vec - An array of at least four double values. The x component of the vector is set to the value of the first element of the array, the y component is set to the value of the second element of the array, the z component is set to the value of the third element of the array, and the w component is set to the value of the fourth element of the array.

Vec4d

public Vec4d(Vec4d vec)
Constructor that initializes the components of the Vec4d object with the components taken from another Vec4d object.

The following example demonstrates how to create a Vec4d object that is an exact copy of another Vec4d object:

 Vec4d given_vec = ...;
 Vec4d vec = new Vec4d(given_vec);
 

Parameters:
vec - The other vector used to initialize the new vector.
Method Detail

getX

public final double getX()
Returns the value of the x component.

The following example demonstrates how to print the x component of a Vec4d object to the console:

 Vec4d vec = ...;
 System.out.println("x component = " + vec.getX());
 

Returns:
The value of the x component

getY

public final double getY()
Returns the value of the y component.

The following example demonstrates how to print the y component of a Vec4d object to the console:

 Vec4d vec = ...;
 System.out.println("y component = " + vec.getY());
 

Returns:
The value of the y component

getZ

public final double getZ()
Returns the value of the z component.

The following example demonstrates how to print the z component of a Vec4d object to the console:

 Vec4d vec = ...;
 System.out.println("z component = " + vec.getZ());
 

Returns:
The value of the z component

getW

public final double getW()
Returns the value of the w component.

The following example demonstrates how to print the w component of a Vec4d object to the console:

 Vec4d vec = ...;
 System.out.println("w component = " + vec.getW());
 

Returns:
The value of the w component

get

public final void get(double[] vec)
Returns the values of the x, y, z and w components.

The following example prints the components of a Vec4d object to the console:

 Vec4d vec = ...;
 double[] vector_components = new double[4];
 vec.get(vector_components);
 System.out.println("x component = " + vector_components[0]);
 System.out.println("y component = " + vector_components[1]);
 System.out.println("z component = " + vector_components[2]);
 System.out.println("w component = " + vector_components[3]);
 

Parameters:
vec - A double array that gets filled with the components of the vector. This array must have at least four elements. The first element of the array is set to the x component of the vector, the second element of the array is set to the y component of the vector, the third element of the array is set to the z component of the vector, and the fourth element of the array is set to the w component of the vector.

equals

public final boolean equals(java.lang.Object obj)
Compares the vector to another object. The result is true if the object is not null and is a Vec4d object and the components of the other Vec4d object are the same as the components of this vector.

The following example compares two vectors and prints the result to the console:

 Vec4d vec1 = ...;
 Vec4d vec2 = ...;
 System.out.println("Vectors are the same: " + vec1.equals(vec2));
 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare the vector to
Returns:
true when the vectors are equal, false otherwise

toString

public final java.lang.String toString()
Converts the vector to a string. The string representation consists of the x component, the y component, the z component and the w component, separated by space characters.

The following example prints the string representation of a Vec4d object to the console:

 Vec4d vec = ...;
 System.out.println("Vector = " + vec.toString());
 

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the vector

valueOf

public static final Vec4d valueOf(java.lang.String str)
Converts a string to a Vec4d object. The string must consist of the x, y, z and w components, separated by space characters.

The following example creates a new Vec4d object:

 Vec4d vec = Vec4d.valueOf("1.0 2.0 3.0 4.0");
 

Parameters:
str - The string representation of the vector.
Returns:
The new Vec4d object, parsed from the string.