Class PathVector
java.lang.Object
de.bsommerfeld.pathetic.api.wrapper.PathVector
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 booleanstatic doublecomputeDistance(PathVector A, PathVector B, PathVector C) Computes the perpendicular distance from pointAto the infinite line defined by pointsBandC.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.static PathVectorof(double x, double y, double z) Creates a newPathVectorinstance with the specified components.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
-
of
Creates a newPathVectorinstance with the specified components.- Parameters:
x- The x-component of the vector.y- The y-component of the vector.z- The z-component of the vector.- Returns:
- A new
PathVectorinstance.
-
computeDistance
Computes the perpendicular distance from pointAto the infinite line defined by pointsBandC.If
BandCcoincide (or are numerically indistinguishable), the line degenerates to a single point and the Euclidean distance fromAtoBis returned.- Parameters:
A- The point represented as aPathVector. Must not benull.B- The first reference point of the line represented as aPathVector. Must not benull.C- The second reference point of the line represented as aPathVector. Must not benull.- Returns:
- The perpendicular distance from
Ato the line throughBandC, or the distance fromAtoBif the line degenerates. - Throws:
NullPointerException- if any argument isnull.
-
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.
-
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()
-