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
-
PI
-
-
PI2
-
-
r
- The r component of the polar view of the vector; never
set directly, use setr instead.
-
t
- The theta component of the polar view of the vector; never
set directly, use sett instead.
-
x
- The x component of the cartesian view of the vector; never
set directly, use setx instead.
-
y
- The y component of the cartesian view of the vector; never
set directly, use sety instead.
-
Vec2()
- Create a new vector, (1,0).
-
Vec2(double, double)
- Create a new vector, (x0,y0).
-
Vec2(Vec2)
- Create a new vector by copying the input parameter.
-
add(Vec2)
- Add another vector to self, this = this + other
-
main(String[])
- A test routine.
-
normalize(double)
- Same as setr.
-
octant()
-
Provides info on which octant (0-7) the vector lies in.
-
quadrant()
-
Provides info on which quadrant (0-3) the vector lies in.
-
rotate(double)
- Rotate the vector.
-
setr(double)
- Set r.
-
sett(double)
- Set t.
-
setx(double)
- Set the x component.
-
sety(double)
- Set the y component.
-
sub(Vec2)
- Subtract other vector from self, this = this - other
-
toString()
- Generate a string value for the vector.
x
public double x
- The x component of the cartesian view of the vector; never
set directly, use setx instead.
- See Also:
- setx
y
public double y
- The y component of the cartesian view of the vector; never
set directly, use sety instead.
- See Also:
- sety
t
public double t
- The theta component of the polar view of the vector; never
set directly, use sett instead.
- See Also:
- sett
r
public double r
- The r component of the polar view of the vector; never
set directly, use setr instead.
- See Also:
- setr
PI2
public static final double PI2
PI
public static final double PI
Vec2
public Vec2()
- Create a new vector, (1,0).
Vec2
public Vec2(double x0,
double y0)
- Create a new vector, (x0,y0).
- Parameters:
- x0 - the x component.
- y0 - the y component.
Vec2
public Vec2(Vec2 v)
- Create a new vector by copying the input parameter.
- Parameters:
- v - Vec2, the vector to copy.
setx
public void setx(double newx)
- Set the x component. t and r are reset as well.
- Parameters:
- newx - the x component.
sety
public void sety(double newy)
- Set the y component. t and r are reset as well.
- Parameters:
- newy - the x component.
sett
public void sett(double newt)
- Set t. x and y are reset as well.
- Parameters:
- newt - the t component.
setr
public void setr(double newr)
- Set r. x, y and t may be reset as well.
- Parameters:
- newr - the r component.
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.
sub
public void sub(Vec2 other)
- Subtract other vector from self, this = this - other
- Parameters:
- other - the vector to subtract.
normalize
public void normalize(double newr)
- Same as setr. Kept for comatibility.
- Parameters:
- newr - the r component.
add
public void add(Vec2 other)
- Add another vector to self, this = this + other
- Parameters:
- other - the vector to add.
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.
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.
toString
public String toString()
- Generate a string value for the vector.
- Returns:
- "(x,y) (r,t)"
- Overrides:
- toString in class Object
main
public static void main(String args[])
- A test routine.
All Packages Class Hierarchy This Package Previous Next Index