|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--fi.utu.cs.physics.Tuple2
|
+--fi.utu.cs.physics.Vector2
A two-component vector of double-precision floating point values.
| Field Summary | |
static Vector2 |
ZERO
A vector with the length 0.0. |
| Constructor Summary | |
Vector2(double dx,
double dy)
Creates a new two-component vector with the given values. |
|
Vector2(double x1,
double y1,
double x2,
double y2)
Creates a new two-component vector from the given points. |
|
Vector2(Point2 source,
Point2 target)
Creates a new two-component vector from the given points. |
|
| Method Summary | |
void |
add(double dx,
double dy)
Adds values to the components. |
void |
add(Vector2 other)
Adds the components of other to the components. |
double |
angle(Vector2 other)
Returns the angle between this vector and the vector other. |
int |
compareTo(java.lang.Object o)
Returns a negative integer, zero, or a positive integer as the length of this vector is less than, equal to, or greater than the length of vector o. |
double |
getDeltaX()
Returns the horizontal component. |
double |
getDeltaY()
Returns the vertical component. |
boolean |
isInTheSameQuadrant(Vector2 other)
Returns whether the vector other resides in the
same coordinate quadrant as this vector. |
double |
length()
Returns the length of this vector. |
double |
lengthSquared()
Returns the squared length of this vector. |
void |
multiply(double s)
Multiplies the vector with the scalar s. |
Vector2 |
project(Vector2 other)
Returns a projection of the vector other to this
vector. |
void |
rotate(double r)
Rotates the vector counterclockwise. |
void |
rotate180()
Rotates the vector 180 degrees counterclockwise. |
void |
rotate270()
Rotates the vector 270 degrees counterclockwise. |
void |
rotate90()
Rotates the vector 90 degrees counterclockwise. |
double |
scalarProduct(Vector2 other)
Returns the scalar product of this vector and the vector other. |
void |
set(double dx,
double dy)
Sets the horizontal and vertical component. |
void |
set(Point2 source,
Point2 target)
Sets the horizontal and vertical components to correspond the transfer from the point source to the point
target. |
void |
set(Vector2 v)
Sets the horizontal and vertical components to the same values as in other. |
void |
setDeltaX(double dx)
Sets the horizontal component to the value dx. |
void |
setDeltaY(double dy)
Sets the vertical component to the value dy. |
Point2 |
transfer(Point2 source)
Creates and returns a point that is transfered from the point source according to this vector.
|
Vector2 |
unitVector()
Returns a unit vector corresponding to this vector. |
| Methods inherited from class fi.utu.cs.physics.Tuple2 |
add, clone, equals, firstElementSign, getFirstElement, getSecondElement, hashCode, max, min, negate, negateFirstElement, negateSecondElement, secondElementSign, set, setFirstElement, setSecondElement, swap, toString |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final Vector2 ZERO
| Constructor Detail |
public Vector2(double dx,
double dy)
public Vector2(double x1,
double y1,
double x2,
double y2)
this.getDeltaX() == x2 - x1
and this.getDeltaY() == y2 - y1.
public Vector2(Point2 source,
Point2 target)
this.getDeltaX() == target.getX() - source.getX()
and this.getDeltaY() == target.getY() - source.getY().
| Method Detail |
public double getDeltaX()
public double getDeltaY()
public void setDeltaX(double dx)
dx.
public void setDeltaY(double dy)
dy.
public void set(double dx,
double dy)
set in class Tuple2dx - The value of the horizontal component.dy - The value of the vertical component.set(Point2,Point2),
set(Vector2)
public void set(Point2 source,
Point2 target)
source to the point
target. After the operation,
this.getDeltaX() = target.getX() - this.getX() and
this.getDeltaY() = target.getY() - this.getY().
set(Vector2)public void set(Vector2 v)
other.
public double length()
public double lengthSquared()
public void add(double dx,
double dy)
add in class Tuple2dx - The value added to the horizontal component.dy - The value added to the vertical component.add(Vector2)public void add(Vector2 other)
other to the components.
public void multiply(double s)
s.
multiply in class Tuple2public double scalarProduct(Vector2 other)
other.
public Vector2 unitVector()
this.unitVector().length == 1.0
and this.angle(this.unitVector()) == 0.0.
public Vector2 project(Vector2 other)
other to this
vector.
public double angle(Vector2 other)
other.
- Returns:
- angle in radians from the range
[
0.0, Math.PI] - Since:
- 1.1
- See Also:
rotate(double)public Point2 transfer(Point2 source)
source according to this vector.
In the new point, getX() = source.getX() + this.getDeltaX()
and getY() = source.getY() + this.getDeltaY().
public void rotate90()
rotate(double),
rotate180(),
rotate270()public void rotate180()
rotate(double),
rotate90(),
rotate270()public void rotate270()
rotate(double),
rotate90(),
rotate180()public void rotate(double r)
r - The amount of rotation in radians.angle(Vector2),
rotate90(),
rotate180(),
rotate270()public boolean isInTheSameQuadrant(Vector2 other)
other resides in the
same coordinate quadrant as this vector.
public int compareTo(java.lang.Object o)
o.
compareTo in interface java.lang.Comparablejava.lang.ClassCastException - If the argument is not of the type
Vector2.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||