artofillusion.math
Class Vec2

java.lang.Object
  extended by artofillusion.math.Vec2

public class Vec2
extends java.lang.Object

A Vec2 represents a 2 component vector.


Field Summary
 double x
           
 double y
           
 
Constructor Summary
Vec2()
          Create a new Vec2 whose x and y components are equal to 0.0.
Vec2(java.io.DataInputStream in)
          Create a Vec2 by reading in information that was written by writeToFile().
Vec2(double xval, double yval)
          Create a new Vec2 with the specified x and y components.
Vec2(Vec2 v)
          Create a new Vec2 identical to another one.
 
Method Summary
 void add(Vec2 v)
          Add another Vec2 to this one.
 double cross(Vec2 v)
          Calculate the cross product of this vector with another one.
 double distance(Vec2 v)
          Calculate the Euclidean distance between this vector and another one.
 double distance2(Vec2 v)
          Calculate the square of the Euclidean distance between this vector and another one.
 double dot(Vec2 v)
          Calculate the dot product of this vector with another one.
 boolean equals(java.lang.Object o)
          Determine whether two vectors are identical.
 int hashCode()
           
 double length()
          Calculate the length of this vector.
 double length2()
          Calculate the square of the length of this vector.
 Vec2 minus(Vec2 v)
          Calculate the difference between this vector and another one.
 void normalize()
          Scale each component of this vector so that it has a length of 1.
 Vec2 plus(Vec2 v)
          Calculate the sum of this vector and another one.
 void scale(double d)
          Multiply each component of this vector by a constant.
 void set(double xval, double yval)
          Set the x and y components of this Vec2.
 void subtract(Vec2 v)
          Subtract another Vec2 from this one.
 Vec2 times(double d)
          Create a new Vec2 by multiplying each component of this one by a constant.
 java.lang.String toString()
           
static Vec2 vx()
          Create a unit vector which points in the X direction.
static Vec2 vy()
          Create a unit vector which points in the Y direction.
 void writeToFile(java.io.DataOutputStream out)
          Write out a serialized representation of this object.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x

y

public double y
Constructor Detail

Vec2

public Vec2()
Create a new Vec2 whose x and y components are equal to 0.0.


Vec2

public Vec2(double xval,
            double yval)
Create a new Vec2 with the specified x and y components.


Vec2

public Vec2(Vec2 v)
Create a new Vec2 identical to another one.


Vec2

public Vec2(java.io.DataInputStream in)
     throws java.io.IOException
Create a Vec2 by reading in information that was written by writeToFile().

Throws:
java.io.IOException
Method Detail

set

public final void set(double xval,
                      double yval)
Set the x and y components of this Vec2.


dot

public final double dot(Vec2 v)
Calculate the dot product of this vector with another one.


cross

public final double cross(Vec2 v)
Calculate the cross product of this vector with another one. Because the cross product of a pair of Vec2's always points along the Z axis, this returns only its Z component.


plus

public final Vec2 plus(Vec2 v)
Calculate the sum of this vector and another one.


minus

public final Vec2 minus(Vec2 v)
Calculate the difference between this vector and another one.


times

public final Vec2 times(double d)
Create a new Vec2 by multiplying each component of this one by a constant.


equals

public final boolean equals(java.lang.Object o)
Determine whether two vectors are identical.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

length

public final double length()
Calculate the length of this vector.


length2

public final double length2()
Calculate the square of the length of this vector.


add

public final void add(Vec2 v)
Add another Vec2 to this one.


subtract

public final void subtract(Vec2 v)
Subtract another Vec2 from this one.


scale

public final void scale(double d)
Multiply each component of this vector by a constant.


distance

public final double distance(Vec2 v)
Calculate the Euclidean distance between this vector and another one.


distance2

public final double distance2(Vec2 v)
Calculate the square of the Euclidean distance between this vector and another one.


normalize

public final void normalize()
Scale each component of this vector so that it has a length of 1. If this vector has a length of 0, this method has no effect.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

vx

public static Vec2 vx()
Create a unit vector which points in the X direction.


vy

public static Vec2 vy()
Create a unit vector which points in the Y direction.


writeToFile

public void writeToFile(java.io.DataOutputStream out)
                 throws java.io.IOException
Write out a serialized representation of this object.

Throws:
java.io.IOException


Copyright © 1999-2011 by Peter Eastman.