Package eu.woolplatform.utils.geom
Class Vector
- java.lang.Object
-
- eu.woolplatform.utils.geom.Vector
-
public class Vector extends Object
This class defines a vector. It consists of an (x,y) direction.
-
-
Constructor Summary
Constructors Constructor Description Vector(double dx, double dy)Constructs a new vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)static VectorfromAngle(double angle, double length)Creates a new vector with the specified angle and length.doublegetAngle()Returns the angle in degrees for this vector.doublegetDx()Returns the direction along the X axis.doublegetDy()Returns the direction along the Y axis.doublegetLength()Returns the length of this vector.inthashCode()booleanisParallel(Vector other)Returns whether another vector is parallel to this vector.voidrotate(double angle)Rotates this vector by the specified number of degrees.voidsetDx(double dx)Sets the direction along the X axis.voidsetDy(double dy)Sets the direction along the Y axis.StringtoString()
-
-
-
Method Detail
-
fromAngle
public static Vector fromAngle(double angle, double length)
Creates a new vector with the specified angle and length. The vector with direction (1, 0) has angle 0.- Parameters:
angle- the angle in degreeslength- the length- Returns:
- the vector
-
getDx
public double getDx()
Returns the direction along the X axis.- Returns:
- the direction along the X axis
-
setDx
public void setDx(double dx)
Sets the direction along the X axis.- Parameters:
dx- the duration along the X axis
-
getDy
public double getDy()
Returns the direction along the Y axis.- Returns:
- the direction along the Y axis
-
setDy
public void setDy(double dy)
Sets the direction along the Y axis.- Parameters:
dy- the direction along the Y axis
-
rotate
public void rotate(double angle)
Rotates this vector by the specified number of degrees.- Parameters:
angle- the number of degrees
-
getAngle
public double getAngle()
Returns the angle in degrees for this vector. The vector with direction (1, 0) has angle 0. This method returns a value between 0 (inclusive) and 360 (exclusive).- Returns:
- the angle in degrees
-
getLength
public double getLength()
Returns the length of this vector.- Returns:
- the length of this vector
-
isParallel
public boolean isParallel(Vector other)
Returns whether another vector is parallel to this vector. This is also true if the other vector moves in the opposite direction.- Parameters:
other- the other vector- Returns:
- true if the vector is parallel, false otherwise
-
-