|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--EDU.gatech.cc.is.util.Vec2
A class for manipulating 2d vectors. Both polar and cartesian components are always available. The fields x, y, t (theta) and r are directly available for reading, but you should never set them directly. Use setx, sety, sett and setr instead. This (non OO) approach was chosen deliberately for speed reasons; no whining.
+x is right, +y is up. t is in radians with t=0 in the +x direction and t = PI in the -r direction, increasing CCW.
NOTE: Vec2's can have direction without magnitude, i.e. theta has meaning even if x, y and r == 0.
Copyright (c)2000 Tucker Balch
Field Summary | |
static double |
PI
|
static double |
PI2
|
double |
r
The r component of the polar view of the vector; never set directly, use setr instead. |
double |
t
The theta component of the polar view of the vector; never set directly, use sett instead. |
double |
x
The x component of the cartesian view of the vector; never set directly, use setx instead. |
double |
y
The y component of the cartesian view of the vector; never set directly, use sety instead. |
Constructor Summary | |
Vec2()
Create a new vector, (1,0). |
|
Vec2(double x0,
double y0)
Create a new vector, (x0,y0). |
|
Vec2(Vec2 v)
Create a new vector by copying the input parameter. |
Method Summary | |
void |
add(Vec2 other)
Add another vector to self, this = this + other |
java.lang.Object |
clone()
Create a new vector by cloning. |
static void |
main(java.lang.String[] args)
A test routine. |
void |
normalize(double newr)
Same as setr. |
int |
octant()
Provides info on which octant (0-7) the vector lies in. |
int |
quadrant()
Provides info on which quadrant (0-3) the vector lies in. |
void |
rotate(double rot)
Rotate the vector. |
void |
setr(double newr)
Set r. |
void |
sett(double newt)
Set t. |
void |
setx(double newx)
Set the x component. |
void |
sety(double newy)
Set the y component. |
void |
sub(Vec2 other)
Subtract other vector from self, this = this - other |
java.lang.String |
toString()
Generate a string value for the vector. |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public double x
setx(double)
public double y
sety(double)
public double t
sett(double)
public double r
setr(double)
public static final double PI2
public static final double PI
Constructor Detail |
public Vec2()
public Vec2(double x0, double y0)
x0
- the x component.y0
- the y component.public Vec2(Vec2 v)
v
- Vec2, the vector to copy.Method Detail |
public java.lang.Object clone()
v
- Vec2, the vector to copy.public void setx(double newx)
newx
- the x component.public void sety(double newy)
newy
- the x component.public void sett(double newt)
newt
- the t component.public void setr(double newr)
newr
- the r component.public void rotate(double rot)
rot
- how many radians to rotate, CCW is positive.public void sub(Vec2 other)
other
- the vector to subtract.public void normalize(double newr)
newr
- the r component.public void add(Vec2 other)
other
- the vector to add.public int octant()
public int quadrant()
public java.lang.String toString()
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |