Class PathVector
java.lang.Object
de.bsommerfeld.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 aPathVectorwith the specified x, y, and z components. -
Method Summary
Modifier and TypeMethodDescriptionadd(PathVector otherVector) Creates a newPathVectorby adding another vector to this vector.protected booleanclone()static doublecomputeDistance(PathVector A, PathVector B, PathVector C) Computes the distance between a point and a line segment.doubledistance(PathVector otherVector) Calculates the Euclidean distance between this vector and another vector.divide(double value) Creates a newPathVectorby dividing this vector by a scalar value.doubledot(PathVector otherVector) Calculates the dot product of this vector and another vector.booleanCalculates the cross product of this vector and another vector.doublegetX()Returns the x-component of this vector.doublegetY()Returns the y-component of this vector.doublegetZ()Returns the z-component of this vector.inthashCode()doublelength()Calculates the length (magnitude) of this vector.multiply(double value) Creates a newPathVectorby multiplying this vector by a scalar value.Creates a newPathVectorby normalizing this vector.setX(double x) Creates a newPathVectorwith the same y and z components as this vector, but with the x-component set to the given value.setY(double y) Creates a newPathVectorwith the same x and z components as this vector, but with the y-component set to the given value.setZ(double z) Creates a newPathVectorwith the same x and y components as this vector, but with the z-component set to the given value.subtract(PathVector otherVector) Creates a newPathVectorby subtracting another vector from this vector.
-
Constructor Details
-
PathVector
public PathVector(double x, double y, double z) Constructs aPathVectorwith 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 newPathVectorwith 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
PathVectorwith the updated x-component.
-
setY
Creates a newPathVectorwith 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
PathVectorwith the updated y-component.
-
setZ
Creates a newPathVectorwith 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
PathVectorwith the updated z-component.
-
subtract
Creates a newPathVectorby subtracting another vector from this vector.- Parameters:
otherVector- The vector to subtract from this vector.- Returns:
- A new
PathVectorrepresenting the difference.
-
multiply
Creates a newPathVectorby multiplying this vector by a scalar value.- Parameters:
value- The scalar value to multiply by.- Returns:
- A new
PathVectorrepresenting the scaled vector.
-
normalize
Creates a newPathVectorby normalizing this vector. Normalization divides each component of the vector by its magnitude, resulting in a unit vector (length of 1).- Returns:
- A new
PathVectorrepresenting the normalized vector.
-
divide
Creates a newPathVectorby dividing this vector by a scalar value.- Parameters:
value- The scalar value to divide by.- Returns:
- A new
PathVectorrepresenting the divided vector.
-
add
Creates a newPathVectorby adding another vector to this vector.- Parameters:
otherVector- The vector to add to this vector.- Returns:
- A new
PathVectorrepresenting 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
PathVectorrepresenting 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()
-