Class Vec

java.lang.Object
  extended byVec

public class Vec
extends java.lang.Object

Represents homogeneous coords point in 3D, plus algebra.

For CSU540 Computer Graphics class, Spring 2005 CCIS, Northeastern University

Consists of a single 4-element double vector, vec, and various static methods.
Method names ending with "Same" alter the vector argument. Others return a copy.

Version:
26 January 2005
Author:
Bob Futrelle

Field Summary
 double[] vec
          The only (non-static) field, a 4-element array.
 
Constructor Summary
Vec()
          Creates 0.0 vector with homogeneous, vec[3], coord = 1.0.
Vec(double x, double y, double z)
          Creates vector with the three argument values and vec[3] = 1.0.
 
Method Summary
static double innerProd(Vec v1, Vec v2)
          Inner product using the x, y, z components.
static double length(Vec v)
          Computes vector length.
static void main(java.lang.String[] args)
          Tests and prints results of all methods (all are static)
static Vec normalize(Vec v)
          Creates a normalized, unit length, copy of a Vec.
static void normalizeSame(Vec v)
          Normalizes (alters) a Vec to unit length.
static Vec outerProd(Vec v1, Vec v2)
          Outer, or vector, product using the x, y, z components.
 java.lang.String toString()
          Lists the x, y, and z elements of vec.
static Vec vecDiff(Vec v1, Vec v2)
          Difference of two vectors, a static method.
static Vec vecSum(Vec v1, Vec v2)
          Sum of two vectors, a static method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vec

public double[] vec
The only (non-static) field, a 4-element array.

Constructor Detail

Vec

public Vec()
Creates 0.0 vector with homogeneous, vec[3], coord = 1.0.


Vec

public Vec(double x,
           double y,
           double z)
Creates vector with the three argument values and vec[3] = 1.0.

Method Detail

main

public static void main(java.lang.String[] args)
Tests and prints results of all methods (all are static)


toString

public java.lang.String toString()
Lists the x, y, and z elements of vec.


innerProd

public static double innerProd(Vec v1,
                               Vec v2)
Inner product using the x, y, z components.


outerProd

public static Vec outerProd(Vec v1,
                            Vec v2)
Outer, or vector, product using the x, y, z components.

Returns:
A new Vec object containing the product in the vec field.
Can be viewed as the value of this determinant:
 | i  j  k |
 | x  y  z |
 | x' y' z'|
 
where i, j, and k are the unit vectors along the three axes.

vecSum

public static Vec vecSum(Vec v1,
                         Vec v2)
Sum of two vectors, a static method. Homogeneous coordinate remains at 1.0
TO BE COMPLETED

Returns:
Vector sum of two arguments.

vecDiff

public static Vec vecDiff(Vec v1,
                          Vec v2)
Difference of two vectors, a static method. Homogeneous coordinate remains at 1.0
TO BE COMPLETED

Returns:
Vector difference of v1 minus v2

length

public static double length(Vec v)
Computes vector length.

Returns:
length of arg (ignores homogeneous coordinate).

normalize

public static Vec normalize(Vec v)
Creates a normalized, unit length, copy of a Vec.

Returns:
normalized copy of arg.

normalizeSame

public static void normalizeSame(Vec v)
Normalizes (alters) a Vec to unit length.

Parameters:
v - The vector to be scaled to unit length.