@Immutable public final class VectorI2D extends Object implements VectorReadable2DType
A two-dimensional immutable vector type with double elements.
Values of this type are immutable and can therefore be safely accessed from multiple threads.
| Constructor and Description |
|---|
VectorI2D()
Default constructor, initializing the vector with values
[0.0, 0.0,
0.0]. |
VectorI2D(double in_x,
double in_y)
Construct a vector initialized with the given values.
|
VectorI2D(VectorReadable2DType in_v)
Construct a vector initialized with the values given in the vector
v. |
| Modifier and Type | Method and Description |
|---|---|
static VectorI2D |
absolute(VectorReadable2DType v)
Calculate the absolute value of the vector
v. |
static VectorI2D |
add(VectorReadable2DType v0,
VectorReadable2DType v1)
Calculate the element-wise sum of the vectors
v0 and v1. |
static VectorI2D |
addScaled(VectorReadable2DType v0,
VectorReadable2DType v1,
double r)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r. |
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 the vectors
v0 and v1 in
radians. |
static VectorI2D |
clamp(VectorReadable2DType v,
double minimum,
double maximum)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static VectorI2D |
clampByVector(VectorReadable2DType 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. |
static VectorI2D |
clampMaximum(VectorReadable2DType v,
double maximum)
Clamp the elements of the vector
v to the range {@code [-Infinity
.. |
static VectorI2D |
clampMaximumByVector(VectorReadable2DType v,
VectorReadable2DType maximum)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in maximum. |
static VectorI2D |
clampMinimum(VectorReadable2DType v,
double minimum)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static VectorI2D |
clampMinimumByVector(VectorReadable2DType v,
VectorReadable2DType minimum)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in minimum. |
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 VectorI2D |
interpolateLinear(VectorReadable2DType v0,
VectorReadable2DType v1,
double alpha)
Linearly interpolate between
v0 and v1 by the amount alpha. |
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 VectorI2D |
normalize(VectorReadable2DType v)
Normalize the vector
v, preserving its direction but reducing it to
unit length. |
static com.io7m.jfunctional.Pair<VectorI2D,VectorI2D> |
orthoNormalize(VectorReadable2DType v0,
VectorReadable2DType v1)
Orthonormalize and return the vectors
v0 and v1 . |
static VectorI2D |
projection(VectorReadable2DType p,
VectorReadable2DType q)
Calculate the projection of the vector
p onto the vector q. |
static VectorI2D |
scale(VectorReadable2DType v,
double r)
Scale the vector
v by the scalar r. |
static VectorI2D |
subtract(VectorReadable2DType v0,
VectorReadable2DType v1)
Subtract the vector
v1 from the vector v0. |
String |
toString() |
public static final VectorI2D ZERO
public VectorI2D()
[0.0, 0.0,
0.0].public VectorI2D(double in_x,
double in_y)
in_x - The x valuein_y - The y valuepublic VectorI2D(VectorReadable2DType in_v)
v.in_v - The input vectorpublic static VectorI2D absolute(VectorReadable2DType v)
v.v - The input vector(abs v.x, abs v.y)public static VectorI2D add(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and v1.v0 - The left input vectorv1 - The right input vector(v0.x + v1.x, v0.y + v1.y)public static VectorI2D addScaled(VectorReadable2DType v0, VectorReadable2DType v1, double r)
v0 and the
element-wise product of v1 and r.v0 - The left input vectorv1 - The right input vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))public static 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 iff the vectors are almost equal.AlmostEqualDouble.almostEqual(ContextRelative, double, double)public static double angle(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and v1 in
radians.v0 - The left input vectorv1 - The right input vectorpublic static VectorI2D clamp(VectorReadable2DType v, double minimum, double maximum)
v to the range [minimum ..
maximum] inclusive.v - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valuemaximum and at
least minimum.public static VectorI2D clampByVector(VectorReadable2DType v, VectorReadable2DType minimum, VectorReadable2DType maximum)
v to the inclusive range given by
the corresponding elements in minimum and maximum.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 VectorI2D clampMaximum(VectorReadable2DType v, double maximum)
v to the range [-Infinity
.. maximum] inclusive.v - The input vectormaximum - The maximum allowed valuemaximumpublic static VectorI2D clampMaximumByVector(VectorReadable2DType v, VectorReadable2DType maximum)
v to the inclusive range given by
the corresponding elements in maximum.v - The input vectormaximum - The vector containing the maximum acceptable values(min(v.x, maximum.x), min(v.y, maximum.y))public static VectorI2D clampMinimum(VectorReadable2DType v, double minimum)
v to the range [minimum ..
Infinity] inclusive.v - The input vectorminimum - The minimum allowed valueminimumpublic static VectorI2D clampMinimumByVector(VectorReadable2DType v, VectorReadable2DType minimum)
v to the inclusive range given by
the corresponding elements in minimum.v - The input vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y), max(v.z,
minimum.z))public static double distance(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and v1.v0 - The left input vectorv1 - The right input vectorpublic static double dotProduct(VectorReadable2DType v0, VectorReadable2DType v1)
v0 and v1.v0 - The left input vectorv1 - The right input vectorpublic static VectorI2D interpolateLinear(VectorReadable2DType v0, VectorReadable2DType v1, double alpha)
v0 and v1 by the amount alpha.
The alpha parameter controls the degree of interpolation, such
that:
interpolateLinear(v0, v1, 0.0) = v0interpolateLinear(v0, v1, 1.0) = v1v0 - The left input vectorv1 - The right input vectoralpha - The interpolation value, between 0.0 and 1.0(1 - alpha) * v0 + alpha * v1public static double magnitude(VectorReadable2DType v)
v.
Correspondingly, magnitude(normalize(v)) == 1.0.v - The input vectorpublic static double magnitudeSquared(VectorReadable2DType v)
v.v - The input vectorpublic static VectorI2D normalize(VectorReadable2DType v)
v, preserving its direction but reducing it to
unit length.v - The input vectorv but with magnitude
equal to 1.0public static com.io7m.jfunctional.Pair<VectorI2D,VectorI2D> 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 VectorI2D projection(VectorReadable2DType p, VectorReadable2DType q)
p onto the vector q.p - The left vectorq - The right vector((dotProduct p q) / magnitudeSquared q) * qpublic static VectorI2D scale(VectorReadable2DType v, double r)
v by the scalar r.v - The input vectorr - The scaling value(v.x * r, v.y * r)public static VectorI2D subtract(VectorReadable2DType v0, VectorReadable2DType v1)
v1 from the vector v0.v0 - The left input vectorv1 - The right input vector(v0.x - v1.x, v0.y - v1.y)public double getXD()
getXD in interface VectorReadable2DTypepublic double getYD()
getYD in interface VectorReadable2DTypeCopyright © 2017 <code@io7m.com> http://io7m.com