core.math
Class Vec

java.lang.Object
  extended bycore.math.Vec

public class Vec
extends java.lang.Object

an n-dimensional vector = < n, (x0, x1, ..., xn-1) >. This class stores and operates on an arbitrary-dimension vector. Methods that begin with a capital letter modify "this", while methods that begin with a lowercase letter create a new Vec to store the result.


Field Summary
 int dim
          dim = n, the dimension of this vector
static double tolerance
          tolerance is the per-component zero-value maximum
 double[] x
          x[] stores the components of this vector
 
Constructor Summary
Vec(int dim)
          Constructs a zero-vector of "dim"-dimension
Vec(Vec v)
          Constructs a new vector that is a copy of vector "v"
 
Method Summary
 Vec add(Vec v)
          Returns: a new Vec that is the sum of "this" and "v" Requires: "this" and "v" have the same dimension
 Vec Add(Vec v)
          Adds "v" to "this" Returns: resulting "this" Requires: "this" and "v" have the same dimension
 Vec addscaled(Vec v, double s)
          Returns: a new Vec that is the sum of "this" and "s*v" Requires: "this" and "v" have the same dimension
 Vec AddScaled(Vec v, double s)
          Adds "s*v" to "this" Returns: resulting "this" Requires: "this" and "v" have the same dimension
private  void assertDim(Vec v)
          Used internally to verify that "v" has the same dimension as "this"
 Vec copy()
          Returns a copy of "this"
 double dot(Vec v)
          Returns: the dot product of "this" and "v" Requires: "this" and "v" have the same dimension
 boolean equals(Vec v)
          Returns: true if "this" and "v" are equal, false otherwise Requires: "this" and "v" have the same dimension
 boolean isZero()
          Returns: true if "this" is the zero-vector, false otherwise
 double len()
          Returns: the magnitude of "this"
 double len2()
          Returns: the magnitude squared of "this"
 double len3()
          Returns: the magnitude cubed of "this"
 Vec neg()
          Returns: a new Vec that is the opposite of "this"
 Vec Neg()
          Negates "this" Returns: resulting "this"
 Vec newVec()
          Returns a new zero-vector of the same dimension as "this"
 Vec para(Vec d)
          Returns: a new Vec that is the component of "this" parallel to "d" Requires: "d" is not zero
 Vec Para(Vec d)
          Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" is not zero
 Vec paraunit(Vec d)
          Returns: a new Vec that is the component of "this" parallel to "d" Requires: "d" has unit magnitude
 Vec ParaUnit(Vec d)
          Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" has unit magnitude
 Vec perp(Vec d)
          Returns: a new Vec that is the component of "this" perpendicular to "d" Requires: "d" is not zero
 Vec Perp(Vec d)
          Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" is not zero
 Vec perpunit(Vec d)
          Returns: a new Vec that is the component of "this" perpendicular to "d" Requires: "d" has unit magnitude
 Vec PerpUnit(Vec d)
          Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" has unit magnitude
 Vec scale(double s)
          Returns: a new Vec that is "s*this"
 Vec Scale(double s)
          Scales "this" by "s" Returns: resulting "this"
 Vec scale(Vec v)
          Returns: a new Vec that is "this" with its components scaled by "v" Requires: "this" and "v" have the same dimension
 Vec Scale(Vec v)
          Scales each component of "this" by the corresponding component of "v" Returns: resulting "this" Requires: "this" and "v" have the same dimension
 Vec Set(Vec v)
          Sets the value of "this" to that of "v" Returns: resulting "this" Requres: "this" and "v" have the same dimension
 Vec SetZero()
          Sets "this" to be the zero-vector with the same dimension as "this" Returns: resulting "this"
 Vec sub(Vec v)
          Returns: a new Vec that is the difference between "this" and "v" Requires: "this" and "v" have the same dimension
 Vec Sub(Vec v)
          Subtracts "v" from "this" Returns: resulting "this" Requres: "this" and "v" have the same dimension
 Vec2 toVec2()
          Returns: a new Vec2 that is equal to "this" Requires: "this" is 2-dimensional
 Vec3 toVec3()
          Returns: a new Vec3 that is equal to "this" Requires: "this" is 3-dimensional
 Vec unit()
          Returns: a new Vec that is "this" scaled to unit magnitude Requires: "this" is not zero
 Vec Unit()
          Rescales "this" to be of unit magnitude Returns: resulting "this" Requires: "this" is not zero
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dim

public int dim
dim = n, the dimension of this vector


x

public double[] x
x[] stores the components of this vector


tolerance

public static double tolerance
tolerance is the per-component zero-value maximum

Constructor Detail

Vec

public Vec(int dim)
Constructs a zero-vector of "dim"-dimension


Vec

public Vec(Vec v)
Constructs a new vector that is a copy of vector "v"

Method Detail

newVec

public Vec newVec()
Returns a new zero-vector of the same dimension as "this"


copy

public Vec copy()
Returns a copy of "this"


assertDim

private void assertDim(Vec v)
Used internally to verify that "v" has the same dimension as "this"


Set

public Vec Set(Vec v)
Sets the value of "this" to that of "v" Returns: resulting "this" Requres: "this" and "v" have the same dimension


SetZero

public Vec SetZero()
Sets "this" to be the zero-vector with the same dimension as "this" Returns: resulting "this"


isZero

public boolean isZero()
Returns: true if "this" is the zero-vector, false otherwise


equals

public boolean equals(Vec v)
Returns: true if "this" and "v" are equal, false otherwise Requires: "this" and "v" have the same dimension


Add

public Vec Add(Vec v)
Adds "v" to "this" Returns: resulting "this" Requires: "this" and "v" have the same dimension


add

public Vec add(Vec v)
Returns: a new Vec that is the sum of "this" and "v" Requires: "this" and "v" have the same dimension


AddScaled

public Vec AddScaled(Vec v,
                     double s)
Adds "s*v" to "this" Returns: resulting "this" Requires: "this" and "v" have the same dimension


addscaled

public Vec addscaled(Vec v,
                     double s)
Returns: a new Vec that is the sum of "this" and "s*v" Requires: "this" and "v" have the same dimension


Sub

public Vec Sub(Vec v)
Subtracts "v" from "this" Returns: resulting "this" Requres: "this" and "v" have the same dimension


sub

public Vec sub(Vec v)
Returns: a new Vec that is the difference between "this" and "v" Requires: "this" and "v" have the same dimension


Neg

public Vec Neg()
Negates "this" Returns: resulting "this"


neg

public Vec neg()
Returns: a new Vec that is the opposite of "this"


dot

public double dot(Vec v)
Returns: the dot product of "this" and "v" Requires: "this" and "v" have the same dimension


len

public double len()
Returns: the magnitude of "this"


len2

public double len2()
Returns: the magnitude squared of "this"


len3

public double len3()
Returns: the magnitude cubed of "this"


Scale

public Vec Scale(double s)
Scales "this" by "s" Returns: resulting "this"


scale

public Vec scale(double s)
Returns: a new Vec that is "s*this"


Scale

public Vec Scale(Vec v)
Scales each component of "this" by the corresponding component of "v" Returns: resulting "this" Requires: "this" and "v" have the same dimension


scale

public Vec scale(Vec v)
Returns: a new Vec that is "this" with its components scaled by "v" Requires: "this" and "v" have the same dimension


Unit

public Vec Unit()
Rescales "this" to be of unit magnitude Returns: resulting "this" Requires: "this" is not zero


unit

public Vec unit()
Returns: a new Vec that is "this" scaled to unit magnitude Requires: "this" is not zero


Para

public Vec Para(Vec d)
Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" is not zero


para

public Vec para(Vec d)
Returns: a new Vec that is the component of "this" parallel to "d" Requires: "d" is not zero


ParaUnit

public Vec ParaUnit(Vec d)
Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" has unit magnitude


paraunit

public Vec paraunit(Vec d)
Returns: a new Vec that is the component of "this" parallel to "d" Requires: "d" has unit magnitude


Perp

public Vec Perp(Vec d)
Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" is not zero


perp

public Vec perp(Vec d)
Returns: a new Vec that is the component of "this" perpendicular to "d" Requires: "d" is not zero


PerpUnit

public Vec PerpUnit(Vec d)
Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" has unit magnitude


perpunit

public Vec perpunit(Vec d)
Returns: a new Vec that is the component of "this" perpendicular to "d" Requires: "d" has unit magnitude


toVec2

public Vec2 toVec2()
Returns: a new Vec2 that is equal to "this" Requires: "this" is 2-dimensional


toVec3

public Vec3 toVec3()
Returns: a new Vec3 that is equal to "this" Requires: "this" is 3-dimensional