public class YVector extends Object
This vector is an ordered 2 tuple and is defined by two doubles.
Constructor and Description |
---|
YVector(double dx,
double dy)
Creates a new vector with given direction.
|
YVector(double x1,
double y1,
double x2,
double y2)
Creates a new vector, whose direction is given by two points.
|
YVector(YPoint p1)
Creates a new vector, whose direction is given by two points.
|
YVector(YPoint p1,
YPoint p2)
Creates a new vector, whose direction is given by two points.
|
YVector(YVector v)
Creates a new vector which is a copy of another vector.
|
Modifier and Type | Method and Description |
---|---|
static YPoint |
add(YPoint p,
YVector v)
Adds the vector to a point and returns the resulting point.
|
void |
add(YVector v)
Adds a vector to this vector.
|
static YVector |
add(YVector v,
YVector w)
Adds two vectors and returns the result.
|
static double |
addAngle(double a1,
double a2)
Returns the result of the addition of two angles between
0 and 2*Pi . |
static double |
angle(YVector v1,
YVector v2)
Returns the angle (measured in radians) between two vectors in clockwise order (with regards to screen coordinates) from
v1 to v2.
|
static YVector |
getNormal(YVector v)
Returns this vector with unit length.
|
double |
getX()
Gets the first coordinate of the vector.
|
double |
getY()
Gets the second coordinate of the vector.
|
double |
length()
Returns the length of the vector, this is the value of the euclidean norm.
|
void |
norm()
Assigns unit length to the vector.
|
static YVector |
orthoNormal(YVector v)
Returns the vector which is orthogonal to the given one and has unit length.
|
static boolean |
rightOf(YVector v1,
YVector v2)
Returns true if vector v1 is on the right side of v2.
|
YVector |
rotate(double angle)
Returns a new
YVector instance that is obtained by rotating this vector by the given angle (measured in radians)
in clockwise direction (with regards to screen coordinates). |
static double |
scalarProduct(YVector v1,
YVector v2)
Returns the value of the scalar product of two vectors.
|
void |
scale(double factor)
Scales the vector by an factor.
|
String |
toString()
Returns a string representation of this vector.
|
public YVector(double dx, double dy)
dx
- the first coordinatedy
- the second coordinatepublic YVector(double x1, double y1, double x2, double y2)
The vector is defined by (x1 - x2, y1 - y2)
.
x1
- the X-coordinate of the first point.y1
- the Y-coordinate of the first point.x2
- the X-coordinate of the second point.y2
- the Y-coordinate of the second point.public YVector(YPoint p1)
The vector is defined by p1
- p2
.
p1
- The first point.public YVector(YPoint p1, YPoint p2)
The vector is defined by p1
- p2
.
p1
- The first point.p2
- The second point. If no point is spcified, (0,0)
is used instead.public YVector(YVector v)
v
- the vector, whose values are copied.public static final YPoint add(YPoint p, YVector v)
p
- a point.v
- the vector to add to the point.public void add(YVector v)
v
- the vector to add.public static final YVector add(YVector v, YVector w)
v
- first vector to sum.w
- second vector to sum.public static final double addAngle(double a1, double a2)
0
and 2*Pi
.
The result is calculated modulo 2*Pi
.
a1
- a value in [0,2Pi)
.a2
- a value in [0,2Pi)
.2*Pi
.public static final double angle(YVector v1, YVector v2)
Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom.
public double getX()
public double getY()
public double length()
public void norm()
public static final YVector orthoNormal(YVector v)
v
- a vector.public static final boolean rightOf(YVector v1, YVector v2)
public YVector rotate(double angle)
YVector
instance that is obtained by rotating this vector by the given angle (measured in radians)
in clockwise direction (with regards to screen coordinates).
Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom.
angle
- the angle of rotation in radians.public static final double scalarProduct(YVector v1, YVector v2)
v1
- the first vector.v2
- the second vector.v1.x * v2.x + v1.y * v2.y
public void scale(double factor)
factor
- the scale factor, with which the length is multiplied.