All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class EDU.gatech.cc.is.util.Vec2

java.lang.Object
   |
   +----EDU.gatech.cc.is.util.Vec2

public class Vec2
extends Object
implements Cloneable, Serializable
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.

+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)1997, 1998 Tucker Balch

Version:
$Revision: 1.3 $
Author:
Tucker Balch

Variable Index

 o PI
 o PI2
 o r
The r component of the polar view of the vector; never set directly, use setr instead.
 o t
The theta component of the polar view of the vector; never set directly, use sett instead.
 o x
The x component of the cartesian view of the vector; never set directly, use setx instead.
 o y
The y component of the cartesian view of the vector; never set directly, use sety instead.

Constructor Index

 o Vec2()
Create a new vector, (1,0).
 o Vec2(double, double)
Create a new vector, (x0,y0).
 o Vec2(Vec2)
Create a new vector by copying the input parameter.

Method Index

 o add(Vec2)
Add another vector to self, this = this + other
 o main(String[])
A test routine.
 o normalize(double)
Same as setr.
 o octant()
Provides info on which octant (0-7) the vector lies in.
 o quadrant()
Provides info on which quadrant (0-3) the vector lies in.
 o rotate(double)
Rotate the vector.
 o setr(double)
Set r.
 o sett(double)
Set t.
 o setx(double)
Set the x component.
 o sety(double)
Set the y component.
 o sub(Vec2)
Subtract other vector from self, this = this - other
 o toString()
Generate a string value for the vector.

Variables

 o x
 public double x
The x component of the cartesian view of the vector; never set directly, use setx instead.

See Also:
setx
 o y
 public double y
The y component of the cartesian view of the vector; never set directly, use sety instead.

See Also:
sety
 o t
 public double t
The theta component of the polar view of the vector; never set directly, use sett instead.

See Also:
sett
 o r
 public double r
The r component of the polar view of the vector; never set directly, use setr instead.

See Also:
setr
 o PI2
 public static final double PI2
 o PI
 public static final double PI

Constructors

 o Vec2
 public Vec2()
Create a new vector, (1,0).

 o Vec2
 public Vec2(double x0,
             double y0)
Create a new vector, (x0,y0).

Parameters:
x0 - the x component.
y0 - the y component.
 o Vec2
 public Vec2(Vec2 v)
Create a new vector by copying the input parameter.

Parameters:
v - Vec2, the vector to copy.

Methods

 o setx
 public void setx(double newx)
Set the x component. t and r are reset as well.

Parameters:
newx - the x component.
 o sety
 public void sety(double newy)
Set the y component. t and r are reset as well.

Parameters:
newy - the x component.
 o sett
 public void sett(double newt)
Set t. x and y are reset as well.

Parameters:
newt - the t component.
 o setr
 public void setr(double newr)
Set r. x, y and t may be reset as well.

Parameters:
newr - the r component.
 o rotate
 public void rotate(double rot)
Rotate the vector. x, y and t are reset.

Parameters:
rot - how many radians to rotate, CCW is positive.
 o sub
 public void sub(Vec2 other)
Subtract other vector from self, this = this - other

Parameters:
other - the vector to subtract.
 o normalize
 public void normalize(double newr)
Same as setr. Kept for comatibility.

Parameters:
newr - the r component.
 o add
 public void add(Vec2 other)
Add another vector to self, this = this + other

Parameters:
other - the vector to add.
 o octant
 public int octant()
Provides info on which octant (0-7) the vector lies in. 0 indicates 0 radians +- PI/8 1-7 continue CCW.

Returns:
0 - 7, depending on which direction the vector is pointing.
 o quadrant
 public int quadrant()
Provides info on which quadrant (0-3) the vector lies in. 0 indicates 0 radians +- PI/4 1-3 continue CCW.

Returns:
0 - 3, depending on which direction the vector is pointing.
 o toString
 public String toString()
Generate a string value for the vector.

Returns:
"(x,y) (r,t)"
Overrides:
toString in class Object
 o main
 public static void main(String args[])
A test routine.


All Packages  Class Hierarchy  This Package  Previous  Next  Index