core.math
Class Vec2

java.lang.Object
  extended bycore.math.Vec2

public class Vec2
extends java.lang.Object

A 2-dimensional vector = < (x, y) >. This class stores and operates on a 2-dimensional vector. Methods that begin with a capital letter modify "this", while methods that begin with a lowercase letter create a new Vec2 to store the result.


Field Summary
static Vec2[] Cartesian
          do not modify Cartesian an array of the cartesian axes
static Vec2 Invalid
          do not modify Invalid = an invalid Vec
static double tolerance
          do not modify tolerance the per-component zero-value maximum
 double x
          x and y are the components of this vector
static Vec2 Xhat
          do not modify Xhat = the unit x-axis
 double y
          x and y are the components of this vector
static Vec2 Yhat
          do not modify Yhat = the unit y-axis
static Vec2 Zero
          do not modify Zero = the zero vector
 
Constructor Summary
Vec2()
          Constructs a new Vec2 = (0, 0)
Vec2(double x, double y)
          Constructs a new Vec2 = (x, y)
Vec2(Vec v)
          Constructs a new Vec2 = "v" Requires: "v" has dimension 2
Vec2(Vec2 v)
          Constructs a new Vec2 = "v"
 
Method Summary
 Vec2 add(double x, double y)
          Returns: a new Vec2 that is the sum of "this" and (x, y)
 Vec2 Add(double x, double y)
          Adds (x, y) to "this" Returns: resulting "this"
 Vec2 add(Vec2 v)
          Returns: a new Vec2 that is the sum of "this" and "v"
 Vec2 Add(Vec2 v)
          Adds "v" to "this" Returns: resulting "this"
 Vec2 addscaled(double x, double y, double s)
          Returns: a new Vec2 that is the sum of "this" and "s * (x, y)"
 Vec2 AddScaled(double x, double y, double s)
          Adds "s * (x, y)" to "this" Returns: resulting "this"
 Vec2 addscaled(Vec2 v, double s)
          Returns: a new Vec2 that is the sum of "this" and "s*v"
 Vec2 AddScaled(Vec2 v, double s)
          Adds "s*v" to "this" Returns: resulting "this"
 Vec2 copy()
          Returns a copy of "this"
 double cross(Vec2 b)
          Returns: the magnitude of cross product of "this" and "b"
 double dot(double x, double y)
          Returns: the dot product of "this" and (x, y)
 double dot(Vec2 v)
          Returns: the dot product of "this" and "v"
 boolean equals(Vec2 v)
          Returns: true if "this" equals "v", false otherwise
 Vec2 getNew()
          Returns a new Vec2 = (0, 0)
 boolean isZero()
          Returns: true if "this" is zero, 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"
 Vec2 mul(Mat2 m)
          Returns: a new Vec2 that is "m*this"
 Vec2 Mul(Mat2 m)
          Multiplies "this" to the left by "m" Returns: resulting "this"
 Vec2 neg()
          Returns: a new Vec2 that is the opposite of "this"
 Vec2 Neg()
          Negates "this" Returns: resulting "this"
 Vec2 para(Vec2 d)
          Returns: a new Vec2 that is the component of "this" parallel to "d" Requires: "d" is not zero
 Vec2 Para(Vec2 d)
          Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" is not zero
 Vec2 paraunit(Vec2 d)
          Returns: a new Vec2 that is the component of "this" parallel to "d" Requires: "d" has unit magnitude
 Vec2 ParaUnit(Vec2 d)
          Isolates the component of "this" parallel to "d" Returns: resulting "this" Requires: "d" has unit magnitude
 Vec2 perp(Vec2 d)
          Returns: a new Vec2 that is the component of "this" perpendicular to "d" Requires: "d" is not zero
 Vec2 Perp(Vec2 d)
          Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" is not zero
 Vec2 perpunit(Vec2 d)
          Returns: a new Vec2 that is the component of "this" perpendicular to "d" Requires: "d" has unit magnitude
 Vec2 PerpUnit(Vec2 d)
          Isolates the component of "this" perpendicular to "d" Returns: resulting "this" Requires: "d" has unit magnitude
 Vec2 rmul(Mat2 m)
          Returns: a new Vec2 that is "this*m"
 Vec2 RMul(Mat2 m)
          Multiplies "this" to the right by "m" Returns: resulting "this"
 Vec2 scale(double s)
          Returns: a new Vec2 that is "s*this"
 Vec2 Scale(double s)
          Scales "this" by "s" Returns: resulting "this"
 Vec2 scale(Vec2 v)
          Returns: a new Vec2 that is "this" with its components scaled by "v"
 Vec2 Scale(Vec2 v)
          Scales each component of "this" by the corresponding component of "v" Returns: resulting "this"
 Vec2 Set(double x, double y)
          Sets "this" to (x, y) Returns: resulting "this"
 Vec2 Set(Vec v)
          Sets "this" to "v" Returns: resulting "this" Requires: "v" has dimension 2
 Vec2 Set(Vec2 v)
          Sets the value of "this" to that of "v" Returns: resulting "this"
 Vec2 SetZero()
          Sets "this" to zero Returns: resulting "this"
 Vec2 sub(double x, double y)
          Returns: a new Vec2 that is the difference between "this" and (x, y)
 Vec2 Sub(double x, double y)
          Subtracts (x, y) from "this" Returns: resulting "this"
 Vec2 sub(Vec2 v)
          Returns: a new Vec2 that is the difference between "this" and "v"
 Vec2 Sub(Vec2 v)
          Subtracts "v" from "this" Returns: resulting "this"
 Vec toVec()
          Returns: a new Vec that is < 2, "this" >
 javax.vecmath.Vector2d toVector2d()
          Returns: a new Vector2d that equals "this"
 javax.vecmath.Vector2f toVector2f()
          Returns: a new Vector2f that equals "this"
 Vec2 unit()
          Returns: a new Vec2 that is "this" scaled to unit magnitude Requires: "this" is not zero
 Vec2 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

x

public double x
x and y are the components of this vector


y

public double y
x and y are the components of this vector


Zero

public static Vec2 Zero
do not modify Zero = the zero vector


Xhat

public static Vec2 Xhat
do not modify Xhat = the unit x-axis


Yhat

public static Vec2 Yhat
do not modify Yhat = the unit y-axis


Cartesian

public static Vec2[] Cartesian
do not modify Cartesian an array of the cartesian axes


Invalid

public static Vec2 Invalid
do not modify Invalid = an invalid Vec


tolerance

public static double tolerance
do not modify tolerance the per-component zero-value maximum

Constructor Detail

Vec2

public Vec2()
Constructs a new Vec2 = (0, 0)


Vec2

public Vec2(Vec2 v)
Constructs a new Vec2 = "v"


Vec2

public Vec2(double x,
            double y)
Constructs a new Vec2 = (x, y)


Vec2

public Vec2(Vec v)
Constructs a new Vec2 = "v" Requires: "v" has dimension 2

Method Detail

getNew

public Vec2 getNew()
Returns a new Vec2 = (0, 0)


copy

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


Set

public Vec2 Set(Vec2 v)
Sets the value of "this" to that of "v" Returns: resulting "this"


Set

public Vec2 Set(double x,
                double y)
Sets "this" to (x, y) Returns: resulting "this"


Set

public Vec2 Set(Vec v)
Sets "this" to "v" Returns: resulting "this" Requires: "v" has dimension 2


SetZero

public Vec2 SetZero()
Sets "this" to zero Returns: resulting "this"


isZero

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


equals

public boolean equals(Vec2 v)
Returns: true if "this" equals "v", false otherwise


Add

public Vec2 Add(Vec2 v)
Adds "v" to "this" Returns: resulting "this"


Add

public Vec2 Add(double x,
                double y)
Adds (x, y) to "this" Returns: resulting "this"


add

public Vec2 add(Vec2 v)
Returns: a new Vec2 that is the sum of "this" and "v"


add

public Vec2 add(double x,
                double y)
Returns: a new Vec2 that is the sum of "this" and (x, y)


AddScaled

public Vec2 AddScaled(Vec2 v,
                      double s)
Adds "s*v" to "this" Returns: resulting "this"


AddScaled

public Vec2 AddScaled(double x,
                      double y,
                      double s)
Adds "s * (x, y)" to "this" Returns: resulting "this"


addscaled

public Vec2 addscaled(Vec2 v,
                      double s)
Returns: a new Vec2 that is the sum of "this" and "s*v"


addscaled

public Vec2 addscaled(double x,
                      double y,
                      double s)
Returns: a new Vec2 that is the sum of "this" and "s * (x, y)"


Sub

public Vec2 Sub(Vec2 v)
Subtracts "v" from "this" Returns: resulting "this"


Sub

public Vec2 Sub(double x,
                double y)
Subtracts (x, y) from "this" Returns: resulting "this"


sub

public Vec2 sub(Vec2 v)
Returns: a new Vec2 that is the difference between "this" and "v"


sub

public Vec2 sub(double x,
                double y)
Returns: a new Vec2 that is the difference between "this" and (x, y)


Neg

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


neg

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


dot

public double dot(Vec2 v)
Returns: the dot product of "this" and "v"


dot

public double dot(double x,
                  double y)
Returns: the dot product of "this" and (x, y)


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 Vec2 Scale(double s)
Scales "this" by "s" Returns: resulting "this"


scale

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


Scale

public Vec2 Scale(Vec2 v)
Scales each component of "this" by the corresponding component of "v" Returns: resulting "this"


scale

public Vec2 scale(Vec2 v)
Returns: a new Vec2 that is "this" with its components scaled by "v"


Unit

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


unit

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


cross

public double cross(Vec2 b)
Returns: the magnitude of cross product of "this" and "b"


Para

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


para

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


ParaUnit

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


paraunit

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


Perp

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


perp

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


PerpUnit

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


perpunit

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


Mul

public Vec2 Mul(Mat2 m)
Multiplies "this" to the left by "m" Returns: resulting "this"


mul

public Vec2 mul(Mat2 m)
Returns: a new Vec2 that is "m*this"


RMul

public Vec2 RMul(Mat2 m)
Multiplies "this" to the right by "m" Returns: resulting "this"


rmul

public Vec2 rmul(Mat2 m)
Returns: a new Vec2 that is "this*m"


toVec

public Vec toVec()
Returns: a new Vec that is < 2, "this" >


toVector2d

public javax.vecmath.Vector2d toVector2d()
Returns: a new Vector2d that equals "this"


toVector2f

public javax.vecmath.Vector2f toVector2f()
Returns: a new Vector2f that equals "this"