Class PathVector
java.lang.Object
de.metaphoriker.pathetic.api.wrapper.PathVector
- All Implemented Interfaces:
Cloneable
Represents a 3D vector within a pathfinding context. This class encapsulates the x, y, and z
components of a vector and provides methods for vector operations such as addition, subtraction,
dot product, cross product, and normalization.
-
Constructor Summary
ConstructorsConstructorDescriptionPathVector
(double x, double y, double z) Constructs aPathVector
with the specified x, y, and z components. -
Method Summary
Modifier and TypeMethodDescriptionadd
(PathVector otherVector) Creates a newPathVector
by adding another vector to this vector.protected boolean
clone()
static double
computeDistance
(PathVector A, PathVector B, PathVector C) Computes the distance between a point and a line segment.double
distance
(PathVector otherVector) Calculates the Euclidean distance between this vector and another vector.divide
(double value) Creates a newPathVector
by dividing this vector by a scalar value.double
dot
(PathVector otherVector) Calculates the dot product of this vector and another vector.boolean
Calculates the cross product of this vector and another vector.double
getX()
Returns the x-component of this vector.double
getY()
Returns the y-component of this vector.double
getZ()
Returns the z-component of this vector.int
hashCode()
double
length()
Calculates the length (magnitude) of this vector.multiply
(double value) Creates a newPathVector
by multiplying this vector by a scalar value.Creates a newPathVector
by normalizing this vector.setX
(double x) Creates a newPathVector
with the same y and z components as this vector, but with the x-component set to the given value.setY
(double y) Creates a newPathVector
with the same x and z components as this vector, but with the y-component set to the given value.setZ
(double z) Creates a newPathVector
with the same x and y components as this vector, but with the z-component set to the given value.subtract
(PathVector otherVector) Creates a newPathVector
by subtracting another vector from this vector.
-
Constructor Details
-
PathVector
public PathVector(double x, double y, double z) Constructs aPathVector
with the specified x, y, and z components.- Parameters:
x
- The x-component of the vector.y
- The y-component of the vector.z
- The z-component of the vector.
-
-
Method Details
-
computeDistance
Computes the distance between a point and a line segment.- Parameters:
A
- The point represented as aPathVector
.B
- The first endpoint of the line segment represented as aPathVector
.C
- The second endpoint of the line segment represented as aPathVector
.- Returns:
- The distance between the point A and the line segment BC.
-
dot
Calculates the dot product of this vector and another vector.- Parameters:
otherVector
- The other vector to calculate the dot product with.- Returns:
- The dot product of the two vectors.
-
length
public double length()Calculates the length (magnitude) of this vector.- Returns:
- The length of the vector.
-
distance
Calculates the Euclidean distance between this vector and another vector.- Parameters:
otherVector
- The other vector to calculate the distance to.- Returns:
- The distance between the two vectors.
-
setX
Creates a newPathVector
with the same y and z components as this vector, but with the x-component set to the given value.- Parameters:
x
- The new x-component.- Returns:
- A new
PathVector
with the updated x-component.
-
setY
Creates a newPathVector
with the same x and z components as this vector, but with the y-component set to the given value.- Parameters:
y
- The new y-component.- Returns:
- A new
PathVector
with the updated y-component.
-
setZ
Creates a newPathVector
with the same x and y components as this vector, but with the z-component set to the given value.- Parameters:
z
- The new z-component.- Returns:
- A new
PathVector
with the updated z-component.
-
subtract
Creates a newPathVector
by subtracting another vector from this vector.- Parameters:
otherVector
- The vector to subtract from this vector.- Returns:
- A new
PathVector
representing the difference.
-
multiply
Creates a newPathVector
by multiplying this vector by a scalar value.- Parameters:
value
- The scalar value to multiply by.- Returns:
- A new
PathVector
representing the scaled vector.
-
normalize
Creates a newPathVector
by normalizing this vector. Normalization divides each component of the vector by its magnitude, resulting in a unit vector (length of 1).- Returns:
- A new
PathVector
representing the normalized vector.
-
divide
Creates a newPathVector
by dividing this vector by a scalar value.- Parameters:
value
- The scalar value to divide by.- Returns:
- A new
PathVector
representing the divided vector.
-
add
Creates a newPathVector
by adding another vector to this vector.- Parameters:
otherVector
- The vector to add to this vector.- Returns:
- A new
PathVector
representing the sum.
-
getCrossProduct
Calculates the cross product of this vector and another vector.- Parameters:
o
- The other vector to calculate the cross product with.- Returns:
- A new
PathVector
representing the cross product.
-
clone
-
getX
public double getX()Returns the x-component of this vector.- Returns:
- The x-component.
-
getY
public double getY()Returns the y-component of this vector.- Returns:
- The y-component.
-
getZ
public double getZ()Returns the z-component of this vector.- Returns:
- The z-component.
-
equals
-
canEqual
-
hashCode
public int hashCode()
-