|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectVelocity
This class models a velocity vector (direction and magnitude) for a system of x-y coordinates.
Constructor Summary | |
Velocity(double deltaX,
double deltaY)
Initialize a new Velocity object, remembering the given (dx,dy) direction. |
Method Summary | |
void |
bounceHorizontal()
Bounce the vector as though it were bouncing off of a wall. |
void |
bounceVertical()
Bounce the vector as though it were bouncing off of the floor or the ceiling. |
double |
getDX()
Get the change in x per unit time represented by this vector. |
double |
getDY()
Get the change in y per unit time represented by this vector. |
double |
magnitude()
Return the magnitude (the length) of this vector. |
void |
rotate(double degrees)
Turn the direction vector through a counter-clockwise angle specified in degrees. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Velocity(double deltaX, double deltaY)
deltaX
- the change in x per unit timedeltaY
- the change in y per unit timeMethod Detail |
public void bounceHorizontal()
public void bounceVertical()
public void rotate(double degrees)
radians = Math.toRadians(degrees); rx = Math.cos(radians)*dx - Math.sin(radians)*dy; ry = Math.sin(radians)*dx + Math.cos(radians)*dy;Note that since the functions Math.sin(radians) and Math.cos(radians) take their arguments in radians, the conversion from degrees to radians must be performed before calculating the new dx and dy values, as shown above.
degrees
- the counter-clockwise angle through which to rotate
this direction vectorpublic double magnitude()
Math.sqrt(dx*dx+dy*dy)
public double getDX()
public double getDY()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |