raytracer.internal
Class Vector

java.lang.Object
  |
  +--raytracer.internal.Vector

public class Vector
extends java.lang.Object

A vector in three dimensions


Constructor Summary
Vector(float x, float y, float z)
          Creates the vector (x,y,z)
 
Method Summary
 Vector crossProduct(Vector v)
          Calculates the vector cross product
 float dotProduct(Vector v)
          Calculates the vector dot product
 Vector invert()
          Inverts a vector componentwise
 float length()
          Calculates the length of the vector
 Vector normalize()
          Scales the vector such that the length equals one
 Vector reflect(Vector normal)
          Reflects a vector at a plane with the given normal
 Vector scale(float t)
          Scales the vector by the given factor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vector

public Vector(float x,
              float y,
              float z)
Creates the vector (x,y,z)

Method Detail

length

public float length()
Calculates the length of the vector

Returns:
Length

normalize

public Vector normalize()
Scales the vector such that the length equals one

Returns:
New vector object with the same direction and length one

scale

public Vector scale(float t)
Scales the vector by the given factor

Parameters:
t - Scaling factor
Returns:
New vector object

dotProduct

public float dotProduct(Vector v)
Calculates the vector dot product

Parameters:
v - Vector for multiplication
Returns:
Dot product

crossProduct

public Vector crossProduct(Vector v)
Calculates the vector cross product

Parameters:
v - Vector for multiplication
Returns:
Cross product

invert

public Vector invert()
Inverts a vector componentwise

Returns:
New inverted vector

reflect

public Vector reflect(Vector normal)
Reflects a vector at a plane with the given normal

Parameters:
normal - Normal vector of the plane to reflect at
Returns:
New reflected vector