Skip navigation links
AlgART Home
net.algart.math.geom

## Class Direction2D

• java.lang.Object
• net.algart.math.geom.Direction2D
• All Implemented Interfaces:
java.lang.Cloneable

public class Direction2D
extends java.lang.Object
implements java.lang.Cloneable

2D direction: an angle φ + corresponding unit vector (cos φ, sin φ)

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

Since:
JDK 1.0
Version:
1.0
Author:
Daniel Alievsky
• ### Method Summary

All Methods
Modifier and Type Method and Description
java.lang.Object clone()
Creates an identical copy of this object.
void copyFrom(Direction2D other)
Sets the current direction identical to other.
boolean equals(java.lang.Object obj)
Indicates whether some other direction is equal to this one, i.e. if the angle returned by getAngle() is the same for both directions.
double getAngle()
Returns the angle: current direction is (cos φ, sin φ), φ = method result (in radians).
double getAngleBetweenDirections(Direction2D other)
Returns the shortes angle (0..π, in radians) between the given directions.
static Direction2D getInstance()
Creates a direction (1, 0), φ = 0.
static Direction2D getInstance(double fi)
Creates a direction (cos φ, sin φ), φ = fi argument (in radians).
double getUnitVectorX()
Returns cos φ, current direction is (cos φ, sin φ).
double getUnitVectorY()
Returns sin φ, current direction is (cos φ, sin φ).
int hashCode()
Returns the hash code for this direction.
void inverse()
Rotates current direction by π: new direction angle will be φ + π, where φ is current direction angle.
void revive()
Revive direction vector: the direction angle φ is changed to an equivalent angle in 0<=φ<2π range (if current φ is not in this range), and the values cos φ and sin φ are recalculated.
void rotate(Rotation2D rot)
Rotates current direction: new direction angle will be φ + rot.getRotationAngle(), where φ is current direction angle.
void rotateBack(Rotation2D rot)
Rotates current direction: new direction angle will be φ - rot.getRotationAngle(), where φ is current direction angle.
void setAngle(double fi)
Sets the angle: new direction will be (cos φ, sin φ), φ = fi argument (in radians).
java.lang.String toString()
Returns some string representation of this object.
• ### Methods inherited from class java.lang.Object

finalize, getClass, notify, notifyAll, wait, wait, wait
• ### Method Detail

• #### getInstance

public static Direction2D getInstance()
Creates a direction (1, 0), φ = 0.
• #### getInstance

public static Direction2D getInstance(double fi)
Creates a direction (cos φ, sin φ), φ = fi argument (in radians).
• #### setAngle

public void setAngle(double fi)
Sets the angle: new direction will be (cos φ, sin φ), φ = fi argument (in radians).
• #### getAngle

public double getAngle()
Returns the angle: current direction is (cos φ, sin φ), φ = method result (in radians).
• #### getUnitVectorX

public double getUnitVectorX()
Returns cos φ, current direction is (cos φ, sin φ).
• #### getUnitVectorY

public double getUnitVectorY()
Returns sin φ, current direction is (cos φ, sin φ).
• #### getAngleBetweenDirections

public double getAngleBetweenDirections(Direction2D other)
Returns the shortes angle (0..π, in radians) between the given directions.
• #### revive

public void revive()
Revive direction vector: the direction angle φ is changed to an equivalent angle in 0<=φ<2π range (if current φ is not in this range), and the values cos φ and sin φ are recalculated. This method should be called sometimes in any long sequence of rotate or rotateBack methods.
• #### rotate

public void rotate(Rotation2D rot)
Rotates current direction: new direction angle will be φ + rot.getRotationAngle(), where φ is current direction angle.
• #### rotateBack

public void rotateBack(Rotation2D rot)
Rotates current direction: new direction angle will be φ - rot.getRotationAngle(), where φ is current direction angle.
• #### inverse

public void inverse()
Rotates current direction by π: new direction angle will be φ + π, where φ is current direction angle.
• #### copyFrom

public void copyFrom(Direction2D other)
Sets the current direction identical to other.
• #### toString

public java.lang.String toString()
Returns some string representation of this object.
Overrides:
toString in class java.lang.Object
• #### hashCode

public int hashCode()
Returns the hash code for this direction.
Overrides:
hashCode in class java.lang.Object
• #### equals

public boolean equals(java.lang.Object obj)
Indicates whether some other direction is equal to this one, i.e. if the angle returned by getAngle() is the same for both directions.

Note: if the difference between directions is 2kπ, the directions are not considered to be equal, though their unit vector are identical.

Overrides:
equals in class java.lang.Object
• #### clone

public java.lang.Object clone()
Creates an identical copy of this object.
Overrides:
clone in class java.lang.Object