Class Vector2D
java.lang.Object
org.locationtech.jts.math.Vector2D
A 2-dimensional mathematical vector represented by double-precision X and Y components.
- Author:
- mbdavis
-
Constructor Summary
ConstructorsConstructorDescriptionVector2D()Vector2D(double x, double y) Vector2D(Coordinate from, Coordinate to) -
Method Summary
Modifier and TypeMethodDescriptiondoubleangle()doubledoubleclone()Creates a copy of this vectorstatic Vector2Dcreate(double x, double y) Creates a new vector with given X and Y components.static Vector2Dcreate(Coordinate coord) Creates a vector from aCoordinate.static Vector2Dcreate(Coordinate from, Coordinate to) Creates a vector with the direction and magnitude of the difference between the to and fromCoordinates.static Vector2DCreates a new vector from an existing one.doubleComputes the distance between this vector and another one.divide(double d) Divides the vector by a scalar value.doubleComputes the dot-product of two vectorsbooleanTests if a vector o has the same values for the x and y components.doublegetComponent(int index) doublegetX()doublegetY()inthashCode()Gets a hashcode for this vector.booleandoublelength()doublemultiply(double d) Multiplies the vector by a scalar value.negate()rotate(double angle) rotateByQuarterCircle(int numQuarters) Rotates a vector by a given number of quarter-circles (i.e. multiples of 90 degrees or Pi/2 radians).toString()Gets a string representation of this vectortranslate(Coordinate coord) weightedSum(Vector2D v, double frac) Computes the weighted sum of this vector with another vector, with this vector contributing a fraction of frac to the total.
-
Constructor Details
-
Vector2D
public Vector2D() -
Vector2D
public Vector2D(double x, double y) -
Vector2D
-
Vector2D
-
Vector2D
-
-
Method Details
-
create
Creates a new vector with given X and Y components.- Parameters:
x- the x componenty- the y component- Returns:
- a new vector
-
create
-
create
Creates a vector from aCoordinate.- Parameters:
coord- the Coordinate to copy- Returns:
- a new vector
-
create
Creates a vector with the direction and magnitude of the difference between the to and fromCoordinates.- Parameters:
from- the origin Coordinateto- the destination Coordinate- Returns:
- a new vector
-
getX
public double getX() -
getY
public double getY() -
getComponent
public double getComponent(int index) -
add
-
subtract
-
multiply
Multiplies the vector by a scalar value.- Parameters:
d- the value to multiply by- Returns:
- a new vector with the value v * d
-
divide
Divides the vector by a scalar value.- Parameters:
d- the value to divide by- Returns:
- a new vector with the value v / d
-
negate
-
length
public double length() -
lengthSquared
public double lengthSquared() -
normalize
-
average
-
weightedSum
Computes the weighted sum of this vector with another vector, with this vector contributing a fraction of frac to the total.In other words,
sum = frac * this + (1 - frac) * v
- Parameters:
v- the vector to sumfrac- the fraction of the total contributed by this vector- Returns:
- the weighted sum of the two vectors
-
distance
Computes the distance between this vector and another one.- Parameters:
v- a vector- Returns:
- the distance between the vectors
-
dot
Computes the dot-product of two vectors- Parameters:
v- a vector- Returns:
- the dot product of the vectors
-
angle
public double angle() -
angle
-
angleTo
-
rotate
-
rotateByQuarterCircle
Rotates a vector by a given number of quarter-circles (i.e. multiples of 90 degrees or Pi/2 radians). A positive number rotates counter-clockwise, a negative number rotates clockwise. Under this operation the magnitude of the vector and the absolute values of the ordinates do not change, only their sign and ordinate index.- Parameters:
numQuarters- the number of quarter-circles to rotate by- Returns:
- the rotated vector.
-
isParallel
-
translate
-
toCoordinate
-
clone
-
toString
-
equals
-
hashCode
-