public class VectorM2D extends Object implements VectorReadable2DType, VectorWritable2DType
A two-dimensional mutable vector type with double precision elements.
Values of this type cannot be accessed safely from multiple threads without explicit synchronization.
| Constructor and Description |
|---|
VectorM2D()
Default constructor, initializing the vector with values
[0.0, 0.0]. |
VectorM2D(double in_x,
double in_y)
Construct a vector initialized with the given values.
|
VectorM2D(VectorReadable2DType in_x)
Construct a vector initialized with the values given in the vector
in_x. |
| Modifier and Type | Method and Description |
|---|---|
static VectorM2D |
absolute(VectorReadable2DType v,
VectorM2D out)
Calculate the absolute values of the elements in vector
v,
saving the result to out. |
static VectorM2D |
absoluteInPlace(VectorM2D v)
Calculate the absolute values of the elements in vector
v,
modifying the vector in-place. |
static VectorM2D |
add(VectorReadable2DType v0,
VectorReadable2DType v1,
VectorM2D out)
Calculate the element-wise sum of the vectors
v0 and
v1, saving the result to out. |
static VectorM2D |
addInPlace(VectorM2D v0,
VectorReadable2DType v1)
Calculate the element-wise sum of the vectors
v0 and
v1, saving the result to v0. |
static VectorM2D |
addScaled(VectorReadable2DType v0,
VectorReadable2DType v1,
double r,
VectorM2D out)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r, saving the
result to out. |
static VectorM2D |
addScaledInPlace(VectorM2D v0,
VectorReadable2DType v1,
double r)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r, saving the
result to v0. |
static boolean |
almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
VectorReadable2DType qa,
VectorReadable2DType qb)
Determine whether or not the vectors
qa and qb
are equal to within the degree of error given in context. |
static double |
angle(VectorReadable2DType v0,
VectorReadable2DType v1)
Calculate the angle between vectors
v0 and v1,
in radians. |
static VectorM2D |
clamp(VectorReadable2DType v,
double minimum,
double maximum,
VectorM2D out)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorM2D |
clampByVector(VectorReadable2DType v,
VectorReadable2DType minimum,
VectorReadable2DType maximum,
VectorM2D out)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum and
maximum, saving the result to out. |
static VectorM2D |
clampByVectorInPlace(VectorM2D v,
VectorReadable2DType minimum,
VectorReadable2DType maximum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum and
maximum, saving the result to v. |
static VectorM2D |
clampInPlace(VectorM2D v,
double minimum,
double maximum)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorM2D |
clampMaximum(VectorReadable2DType v,
double maximum,
VectorM2D out)
Clamp the elements of the vector
v to the range
[-Infinity .. |
static VectorM2D |
clampMaximumByVector(VectorReadable2DType v,
VectorReadable2DType maximum,
VectorM2D out)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in maximum, saving the
result to out. |
static VectorM2D |
clampMaximumByVectorInPlace(VectorM2D v,
VectorReadable2DType maximum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in maximum, saving the
result to v. |
static VectorM2D |
clampMaximumInPlace(VectorM2D v,
double maximum)
Clamp the elements of the vector
v to the range
[-Infinity .. |
static VectorM2D |
clampMinimum(VectorReadable2DType v,
double minimum,
VectorM2D out)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorM2D |
clampMinimumByVector(VectorReadable2DType v,
VectorReadable2DType minimum,
VectorM2D out)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum, saving the
result to out. |
static VectorM2D |
clampMinimumByVectorInPlace(VectorM2D v,
VectorReadable2DType minimum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum, saving the
result to v. |
static VectorM2D |
clampMinimumInPlace(VectorM2D v,
double minimum)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorWritable2DType |
copy(VectorReadable2DType input,
VectorWritable2DType output)
Copy all elements of the vector
input to the vector
output. |
void |
copyFrom2D(VectorReadable2DType in_v)
Set the current vector to the contents of the input vector.
|
static double |
distance(VectorReadable2DType v0,
VectorReadable2DType v1)
Calculate the distance between the two vectors
v0 and
v1. |
static double |
dotProduct(VectorReadable2DType v0,
VectorReadable2DType v1)
Calculate the scalar product of the vectors
v0 and
v1. |
boolean |
equals(Object obj) |
double |
getXD() |
double |
getYD() |
int |
hashCode() |
static VectorM2D |
interpolateLinear(VectorReadable2DType v0,
VectorReadable2DType v1,
double alpha,
VectorM2D r)
Linearly interpolate between
v0 and v1 by the
amount alpha, saving the result to r. |
static double |
magnitude(VectorReadable2DType v)
Calculate the magnitude of the vector
v. |
static double |
magnitudeSquared(VectorReadable2DType v)
Calculate the squared magnitude of the vector
v. |
static VectorM2D |
normalize(VectorReadable2DType v,
VectorM2D out)
Returns a vector with the same orientation as
v but with
magnitude equal to 1.0 in out. |
static VectorM2D |
normalizeInPlace(VectorM2D v)
Returns a vector with the same orientation as
v but with
magnitude equal to 1.0 in v. |
static com.io7m.jfunctional.Pair<VectorM2D,VectorM2D> |
orthoNormalize(VectorReadable2DType v0,
VectorReadable2DType v1)
Orthonormalize and return the vectors
v0 and v1
. |
static void |
orthoNormalizeInPlace(VectorM2D v0,
VectorM2D v1)
Orthonormalize and the vectors
v0 and v1. |
static VectorM2D |
projection(VectorReadable2DType p,
VectorReadable2DType q,
VectorM2D r)
Calculate the projection of the vector
p onto the vector
q, saving the result in r. |
static VectorM2D |
scale(VectorReadable2DType v,
double r,
VectorM2D out)
Scale the vector
v by the scalar r, saving the
result to out. |
static VectorM2D |
scaleInPlace(VectorM2D v,
double r)
Scale the vector
v by the scalar r, saving the
result to v. |
void |
set2D(double in_x,
double in_y)
Set the current
x and y values of the current
vector. |
void |
setXD(double in_x)
Set the current
x value of the current vector. |
void |
setYD(double in_y)
Set the current
y value of the current vector. |
static VectorM2D |
subtract(VectorReadable2DType v0,
VectorReadable2DType v1,
VectorM2D out)
Subtract the vector
v1 from the vector v0,
saving the result to out. |
static VectorM2D |
subtractInPlace(VectorM2D v0,
VectorReadable2DType v1)
Subtract the vector
v1 from the vector v0,
saving the result to v0. |
String |
toString() |
public VectorM2D()
[0.0, 0.0].public VectorM2D(double in_x,
double in_y)
in_x - The x valuein_y - The y valuepublic VectorM2D(VectorReadable2DType in_x)
in_x.in_x - The source vectorpublic static final VectorM2D absolute(VectorReadable2DType v, VectorM2D out)
v,
saving the result to out.v - The input vectorout - The output vector(abs v.x, abs v.y)public static final VectorM2D absoluteInPlace(VectorM2D v)
v,
modifying the vector in-place.v - The input vector(abs v.x, abs v.y)public static final VectorM2D add(VectorReadable2DType v0, VectorReadable2DType v1, VectorM2D out)
v0 and
v1, saving the result to out.v0 - The left input vectorv1 - The right input vectorout - The output vector(v0.x + v1.x, v0.y + v1.y)public static final VectorM2D addInPlace(VectorM2D v0, VectorReadable2DType v1)
v0 and
v1, saving the result to v0.v0 - The left input vectorv1 - The right input vector(v0.x + v1.x, v0.y + v1.y)public static final VectorM2D addScaled(VectorReadable2DType v0, VectorReadable2DType v1, double r, VectorM2D out)
v0 and the
element-wise product of v1 and r, saving the
result to out.v0 - The left input vectorv1 - The right input vectorout - The output vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))public static final VectorM2D addScaledInPlace(VectorM2D v0, VectorReadable2DType v1, double r)
v0 and the
element-wise product of v1 and r, saving the
result to v0.v0 - The left input vectorv1 - The right input vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))public static final boolean almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
VectorReadable2DType qa,
VectorReadable2DType qb)
qa and qb
are equal to within the degree of error given in context.context - The equality contextqa - The left input vectorqb - The right input vectortrue if the vectors are almost equalAlmostEqualDouble.almostEqual(ContextRelative, double, double)public static final double angle(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and v1,
in radians.v0 - The left input vectorv1 - The right input vectorpublic static final VectorM2D clamp(VectorReadable2DType v, double minimum, double maximum, VectorM2D out)
v to the range
[minimum .. maximum] inclusive, saving the result to
out.v - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valueout - The output vectormaximum
and at least minimumpublic static final VectorM2D clampByVector(VectorReadable2DType v, VectorReadable2DType minimum, VectorReadable2DType maximum, VectorM2D out)
v to the inclusive range
given by the corresponding elements in minimum and
maximum, saving the result to out.v - The input vectorminimum - The vector containing the minimum acceptable valuesmaximum - The vector containing the maximum acceptable valuesout - The output vector(min(max(v.x, minimum.x), maximum.x), min(max(v.y, minimum.y), maximum.y))public static final VectorM2D clampByVectorInPlace(VectorM2D v, VectorReadable2DType minimum, VectorReadable2DType maximum)
v to the inclusive range
given by the corresponding elements in minimum and
maximum, saving the result to v.v - The input vectorminimum - The vector containing the minimum acceptable valuesmaximum - The vector containing the maximum acceptable values(min(max(v.x, minimum.x), maximum.x), min(max(v.y, minimum.y), maximum.y))public static final VectorM2D clampInPlace(VectorM2D v, double minimum, double maximum)
v to the range
[minimum .. maximum] inclusive, saving the result to
v.v - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valuemaximum
and at least minimum, in vpublic static final VectorM2D clampMaximum(VectorReadable2DType v, double maximum, VectorM2D out)
v to the range
[-Infinity .. maximum] inclusive, saving the result to
out.v - The input vectorout - The output vectormaximum - The maximum allowed valuemaximumpublic static final VectorM2D clampMaximumByVector(VectorReadable2DType v, VectorReadable2DType maximum, VectorM2D out)
v to the inclusive range
given by the corresponding elements in maximum, saving the
result to out.v - The input vectormaximum - The vector containing the maximum acceptable valuesout - The output vector(min(v.x, maximum.x), min(v.y, maximum.y))public static final VectorM2D clampMaximumByVectorInPlace(VectorM2D v, VectorReadable2DType maximum)
v to the inclusive range
given by the corresponding elements in maximum, saving the
result to v.v - The input vectormaximum - The vector containing the maximum acceptable values(min(v.x, maximum.x), min(v.y, maximum.y))public static final VectorM2D clampMaximumInPlace(VectorM2D v, double maximum)
v to the range
[-Infinity .. maximum] inclusive, saving the result to
v.v - The input vectormaximum - The maximum allowed valuemaximum
, in vpublic static final VectorM2D clampMinimum(VectorReadable2DType v, double minimum, VectorM2D out)
v to the range
[minimum .. Infinity] inclusive, saving the result to
out.v - The input vectorout - The output vectorminimum - The minimum allowed valueminimumpublic static final VectorM2D clampMinimumByVector(VectorReadable2DType v, VectorReadable2DType minimum, VectorM2D out)
v to the inclusive range
given by the corresponding elements in minimum, saving the
result to out.v - The input vectorout - The output vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y))public static final VectorM2D clampMinimumByVectorInPlace(VectorM2D v, VectorReadable2DType minimum)
v to the inclusive range
given by the corresponding elements in minimum, saving the
result to v.v - The input vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y)) , in
vpublic static final VectorM2D clampMinimumInPlace(VectorM2D v, double minimum)
v to the range
[minimum .. Infinity] inclusive, saving the result to
v.v - The input vectorminimum - The minimum allowed valueminimum, in v.public static final VectorWritable2DType copy(VectorReadable2DType input, VectorWritable2DType output)
input to the vector
output.input - The input vectoroutput - The output vectorpublic static final double distance(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and
v1.v0 - The left input vectorv1 - The right input vectorpublic static final double dotProduct(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and
v1.v0 - The left input vectorv1 - The right input vectorpublic static final VectorM2D interpolateLinear(VectorReadable2DType v0, VectorReadable2DType v1, double alpha, VectorM2D r)
v0 and v1 by the
amount alpha, saving the result to r.
The alpha parameter controls the degree of interpolation,
such that:
interpolateLinear(v0, v1, 0.0, r) -> r = v0interpolateLinear(v0, v1, 1.0, r) -> r = v1v0 - The left input vector.v1 - The right input vector.alpha - The interpolation value, between 0.0 and
1.0.r - The result vector.rpublic static final double magnitude(VectorReadable2DType v)
v.
Correspondingly, magnitude(normalize(v)) == 1.0.v - The input vectorpublic static final double magnitudeSquared(VectorReadable2DType v)
v.v - The input vectorpublic static final VectorM2D normalize(VectorReadable2DType v, VectorM2D out)
v but with
magnitude equal to 1.0 in out. The function
returns the zero vector iff the input is the zero vector.v - The input vectorout - The output vectorpublic static final VectorM2D normalizeInPlace(VectorM2D v)
v but with
magnitude equal to 1.0 in v. The function
returns the zero vector iff the input is the zero vector.v - The input vectorpublic static final com.io7m.jfunctional.Pair<VectorM2D,VectorM2D> orthoNormalize(VectorReadable2DType v0, VectorReadable2DType v1)
Orthonormalize and return the vectors v0 and v1
.
See GSP
v0 - The left vectorv1 - The right vector(v0, v1), orthonormalized.public static final void orthoNormalizeInPlace(VectorM2D v0, VectorM2D v1)
Orthonormalize and the vectors v0 and v1.
See GSP
v0 - The left vectorv1 - The right vectorpublic static final VectorM2D projection(VectorReadable2DType p, VectorReadable2DType q, VectorM2D r)
p onto the vector
q, saving the result in r.p - The left vectorq - The right vectorr - The output vector((dotProduct p q) / magnitudeSquared q) * qpublic static final VectorM2D scale(VectorReadable2DType v, double r, VectorM2D out)
v by the scalar r, saving the
result to out.v - The input vectorr - The scaling valueout - The output vector(v.x * r, v.y * r)public static final VectorM2D scaleInPlace(VectorM2D v, double r)
v by the scalar r, saving the
result to v.v - The input vectorr - The scaling value(v.x * r, v.y * r)public static final VectorM2D subtract(VectorReadable2DType v0, VectorReadable2DType v1, VectorM2D out)
v1 from the vector v0,
saving the result to out.v0 - The left input vectorv1 - The right input vectorout - The output vector(v0.x - v1.x, v0.y - v1.y)public static final VectorM2D subtractInPlace(VectorM2D v0, VectorReadable2DType v1)
v1 from the vector v0,
saving the result to v0.v0 - The left input vectorv1 - The right input vector(v0.x - v1.x, v0.y - v1.y)public final void copyFrom2D(VectorReadable2DType in_v)
VectorWritable2DTypecopyFrom2D in interface VectorWritable2DTypein_v - The input vectorpublic final double getXD()
getXD in interface VectorReadable2DTypepublic final double getYD()
getYD in interface VectorReadable2DTypepublic final void set2D(double in_x,
double in_y)
VectorWritable2DTypex and y values of the current
vector.set2D in interface VectorWritable2DTypein_x - The new x value.in_y - The new y value.public final void setXD(double in_x)
VectorWritable2DTypex value of the current vector.setXD in interface VectorWritable2DTypein_x - The new x value.public final void setYD(double in_y)
VectorWritable2DTypey value of the current vector.setYD in interface VectorWritable2DTypein_y - The new y value.Copyright © 2015 <code@io7m.com> http://io7m.com