Package org.locationtech.jts.math
Class Vector3D
- java.lang.Object
-
- org.locationtech.jts.math.Vector3D
-
public class Vector3D extends java.lang.ObjectRepresents a vector in 3-dimensional Cartesian space.- Author:
- mdavis
-
-
Constructor Summary
Constructors Constructor Description Vector3D(double x, double y, double z)Creates a vector with the givne components.Vector3D(Coordinate v)Creates a new 3D vector from aCoordinate.Vector3D(Coordinate from, Coordinate to)Creates a new vector with the direction and magnitude of the difference between the to and fromCoordinates.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3Dadd(Vector3D v)Computes a vector which is the sum of this vector and the given vector.static Vector3Dcreate(double x, double y, double z)Creates a new vector with given X, Y and Z components.static Vector3Dcreate(Coordinate coord)Creates a vector from a 3DCoordinate.Vector3Ddivide(double d)Creates a new vector which has the same direction and with length equals to the length of this vector divided by the scalar valued.static doubledot(Coordinate v1, Coordinate v2)Computes the 3D dot-product of twoCoordinates.static doubledot(Coordinate A, Coordinate B, Coordinate C, Coordinate D)Computes the dot product of the 3D vectors AB and CD.doubledot(Vector3D v)Computes the dot-product of two vectorsbooleanequals(java.lang.Object o)Tests if a vector o has the same values for the components.doublegetX()Gets the X component of this vector.doublegetY()Gets the Y component of this vector.doublegetZ()Gets the Z component of this vector.inthashCode()Gets a hashcode for this vector.doublelength()Computes the length of this vector.static doublelength(Coordinate v)Computes the length of a vector.Vector3Dnormalize()Computes a vector having identical direction but normalized to have length 1.static Coordinatenormalize(Coordinate v)Computes a vector having identical direction but normalized to have length 1.Vector3Dsubtract(Vector3D v)Computes a vector which is the difference of this vector and the given vector.java.lang.StringtoString()Gets a string representation of this vector
-
-
-
Constructor Detail
-
Vector3D
public Vector3D(Coordinate v)
Creates a new 3D vector from aCoordinate. The coordinate should have the X,Y and Z ordinates specified.- Parameters:
v- the Coordinate to copy
-
Vector3D
public Vector3D(Coordinate from, Coordinate to)
Creates a new vector with the direction and magnitude of the difference between the to and fromCoordinates.- Parameters:
from- the origin Coordinateto- the destination Coordinate
-
Vector3D
public Vector3D(double x, double y, double z)Creates a vector with the givne components.- Parameters:
x- the X componenty- the Y componentz- the Z component
-
-
Method Detail
-
dot
public static double dot(Coordinate A, Coordinate B, Coordinate C, Coordinate D)
Computes the dot product of the 3D vectors AB and CD.- Parameters:
A- the start point of the first vectorB- the end point of the first vectorC- the start point of the second vectorD- the end point of the second vector- Returns:
- the dot product
-
create
public static Vector3D create(double x, double y, double z)
Creates a new vector with given X, Y and Z components.- Parameters:
x- the X componenty- the Y componentz- the Z component- Returns:
- a new vector
-
create
public static Vector3D create(Coordinate coord)
Creates a vector from a 3DCoordinate. The coordinate should have the X,Y and Z ordinates specified.- Parameters:
coord- the Coordinate to copy- Returns:
- a new vector
-
dot
public static double dot(Coordinate v1, Coordinate v2)
Computes the 3D dot-product of twoCoordinates.- Parameters:
v1- the first vectorv2- the second vector- Returns:
- the dot product of the vectors
-
getX
public double getX()
Gets the X component of this vector.- Returns:
- the value of the X component
-
getY
public double getY()
Gets the Y component of this vector.- Returns:
- the value of the Y component
-
getZ
public double getZ()
Gets the Z component of this vector.- Returns:
- the value of the Z component
-
add
public Vector3D add(Vector3D v)
Computes a vector which is the sum of this vector and the given vector.- Parameters:
v- the vector to add- Returns:
- the sum of this and
v
-
subtract
public Vector3D subtract(Vector3D v)
Computes a vector which is the difference of this vector and the given vector.- Parameters:
v- the vector to subtract- Returns:
- the difference of this and
v
-
divide
public Vector3D divide(double d)
Creates a new vector which has the same direction and with length equals to the length of this vector divided by the scalar valued.- Parameters:
d- the scalar divisor- Returns:
- a new vector with divided length
-
dot
public double dot(Vector3D v)
Computes the dot-product of two vectors- Parameters:
v- a vector- Returns:
- the dot product of the vectors
-
length
public double length()
Computes the length of this vector.- Returns:
- the length of the vector
-
length
public static double length(Coordinate v)
Computes the length of a vector.- Parameters:
v- a coordinate representing a 3D vector- Returns:
- the length of the vector
-
normalize
public Vector3D normalize()
Computes a vector having identical direction but normalized to have length 1.- Returns:
- a new normalized vector
-
normalize
public static Coordinate normalize(Coordinate v)
Computes a vector having identical direction but normalized to have length 1.- Parameters:
v- a coordinate representing a 3D vector- Returns:
- a coordinate representing the normalized vector
-
toString
public java.lang.String toString()
Gets a string representation of this vector- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representing this vector
-
equals
public boolean equals(java.lang.Object o)
Tests if a vector o has the same values for the components.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- a Vector3D with which to do the comparison.- Returns:
- true if other is a Vector3D with the same values for the x and y components.
-
hashCode
public int hashCode()
Gets a hashcode for this vector.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hashcode for this vector
-
-