public class GVector
extends java.lang.Object
(0, 0) o------------------>x-axis
| . / direction
| .
| .vector
| .
| .
| *
v
y-axis
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.Modifier and Type | Field and Description |
---|---|
double |
x
The public x-coordinate.
|
double |
y
The public y-coordinate.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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).
|
public GVector()
public GVector(java.awt.Point pt)
pt
- the point that becomes a vectorpublic GVector(int x, int y)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorpublic GVector(float x, float y)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorpublic GVector(double x, double y)
x
- the x-coordinate of the vectory
- the y-coordinate of the vectorpublic 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 productpublic double distanceTo(GVector v)
v
- the vector to take for the distance measurementpublic GVector add(GVector v)
v
- the vector to be added to the current vectorpublic GVector invert()
public GVector sub(GVector v)
v
- the vector to be substracted from the current vectorpublic GVector mult(int b)
b
- the integer scale factorpublic GVector mult(float b)
b
- the float scale factorpublic GVector mult(double b)
b
- the double scale factorpublic GVector clone()
clone
in class java.lang.Object
public 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 assumedpublic boolean isEqual(GVector v)
v
- the vector to compare