public class Vector2D
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
protected double |
direction |
protected java.awt.geom.Point2D.Float |
from |
protected double |
length |
protected java.awt.geom.Point2D.Float |
to |
Constructor and Description |
---|
Vector2D(double length,
double direction)
Creates a vector with the given length and direction.
|
Vector2D(java.awt.geom.Point2D.Float from,
java.awt.geom.Point2D.Float to)
Creates a vector using two points.
|
Modifier and Type | Method and Description |
---|---|
Vector2D |
clone() |
double |
getDegree()
Returns the direction of the vector in degrees.
|
double |
getLength()
Returns the magnitude of the vector.
|
Vector2D |
getOrigo()
Shifts a copy of the vector to the origo (0,0).
|
java.awt.geom.Point2D.Float |
getP1()
Returns starting point.
|
java.awt.geom.Point2D.Float |
getP2()
Returns end point.
|
double |
getRadian()
Returns the direction of the vector in radians.
|
void |
multiply(double scale)
Multiplies the vector.
|
protected double |
radianNorm(double radian)
Limits the radian value between 0 and 2 PI.
|
protected void |
setDirection()
Calculates the direction from p1 and p2.
|
void |
setDirection(double rad)
Sets the new direction in radians.
|
void |
setP1(float x,
float y)
Sets starting point.
|
void |
setP1(java.awt.geom.Point2D.Float p1)
Sets starting point.
|
void |
setP2(float x,
float y)
Sets end point.
|
void |
setP2(java.awt.geom.Point2D.Float p2)
Sets end point.
|
void |
shiftWith(java.awt.geom.Point2D.Float p)
Shifts this vector by the given point.
|
java.lang.String |
toString() |
protected double length
protected double direction
protected java.awt.geom.Point2D.Float from
protected java.awt.geom.Point2D.Float to
public Vector2D(double length, double direction)
length
- magnitude of vectordirection
- direction of vector in radians.public Vector2D(java.awt.geom.Point2D.Float from, java.awt.geom.Point2D.Float to)
protected double radianNorm(double radian)
radian
- public double getLength()
public double getRadian()
public double getDegree()
public void setP1(float x, float y)
public void setP1(java.awt.geom.Point2D.Float p1)
public void setP2(float x, float y)
public void setP2(java.awt.geom.Point2D.Float p2)
public java.awt.geom.Point2D.Float getP1()
public java.awt.geom.Point2D.Float getP2()
public Vector2D getOrigo()
public void shiftWith(java.awt.geom.Point2D.Float p)
p
- protected void setDirection()
public void setDirection(double rad)
public java.lang.String toString()
toString
in class java.lang.Object
public void multiply(double scale)
public Vector2D clone()
clone
in class java.lang.Object