|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectch.aplu.util.GVector
public class GVector
Class representing a two-dimensional vector with double coordinates (x, y).
The following situation is assumed:
The direction of the vector is defined as the angle (0..2*pi) of the
vector direction clockwise with reference to the x-coordinate direction.
(0, 0) o------------------>x-axis
| . / direction
| .
| .vector
| .
| .
| *
v
y-axis
| Field Summary | |
|---|---|
double |
x
The public x-coordinate. |
double |
y
The public y-coordinate. |
| Constructor Summary | |
|---|---|
GVector()
Constructs a zero vector (with coordinates (0, 0)). |
|
GVector(double x,
double y)
Constructs a vector from given double x-y-coordinates. |
|
GVector(float x,
float y)
Constructs a vector from given float x-y-coordinates. |
|
GVector(int x,
int y)
Constructs a vector from given integer x-y-coordinates. |
|
GVector(java.awt.Point pt)
Constructs a vector from integer coordinates using jawa.awt.Point. |
|
| Method Summary | |
|---|---|
GVector |
add(GVector v)
Returns a new vector that is the vector sum of the current vector and the given vector. |
GVector |
clone()
Returns a new vector with the same coordinates as the current vector. |
double |
distanceTo(GVector v)
Returns the distance between the current vector and the given vector. |
double |
dot(GVector v)
Returns the scalar product (dot product) of the current vector with the given vector. |
double |
getDirection()
Returns the direction of the vector (range 0..2*pi) |
GVector |
getNormalized()
Returns a new vector with magnitude 1 in the direction of the given vector. |
GVector |
invert()
Returns a new vector with inverted coordinates. |
boolean |
isEqual(GVector v)
Returns true, if the current vector is identical to the given vector. |
boolean |
isIntersecting(GVector imageCenter,
double imageDirection,
java.awt.image.BufferedImage image,
boolean isRotatable)
Returns true, if the current vector (casted to int values) points to a non-transparant pixel of the given image. |
double |
magnitude()
Returns the magnitude (length) of the vector. |
double |
magnitude2()
Returns the square of the magnitude, without squareroot calculation. |
GVector |
mult(double b)
Returns a new vector that is the product by a scalar of the current vector and the given double. |
GVector |
mult(float b)
Returns a new vector that is the product by a scalar of the current vector and the given float. |
GVector |
mult(int b)
Returns a new vector that is the product by a scalar of the current vector and the given integer. |
void |
normalize()
Modifies the vector to unit magnitude. |
void |
rotate(double angle)
Rotates the vector by the specified angle. |
GVector |
sub(GVector v)
Returns a new vector that is the vector difference of the current vector and the given vector. |
java.lang.String |
toString()
Returns a string with the x-y-coordinates in the format (x, y). |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public double x
public double y
| Constructor Detail |
|---|
public GVector()
public GVector(java.awt.Point pt)
pt - the point that becomes a vector
public GVector(int x,
int y)
x - the x-coordinate of the vectory - the y-coordinate of the vector
public GVector(float x,
float y)
x - the x-coordinate of the vectory - the y-coordinate of the vector
public GVector(double x,
double y)
x - the x-coordinate of the vectory - the y-coordinate of the vector| Method Detail |
|---|
public double magnitude()
public double magnitude2()
public void normalize()
public GVector getNormalized()
public double getDirection()
public void rotate(double angle)
angle - the rotation angle (in radian, clockwise)public double dot(GVector v)
v - the vector to take for the dot product
public double distanceTo(GVector v)
v - the vector to take for the distance measurement
public GVector add(GVector v)
v - the vector to be added to the current vector
public GVector invert()
public GVector sub(GVector v)
v - the vector to be substracted from the current vector
public GVector mult(int b)
b - the integer scale factor
public GVector mult(float b)
b - the float scale factor
public GVector mult(double b)
b - the double scale factor
public GVector clone()
clone in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object
public boolean isIntersecting(GVector imageCenter,
double imageDirection,
java.awt.image.BufferedImage image,
boolean isRotatable)
imageCenter - the vector to the center of the imageimageDirection - the direction of the image (angle of edge ulx --> uly
with respect to the positive x-direction (0..2*pi))isRotatable - if true, the imageDirection is considered; otherwise
imageDirection = 0 is assumed
public boolean isEqual(GVector v)
v - the vector to compare
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||