public class Vector3D
extends java.lang.Object
implements java.io.Serializable
Instance of this class are guaranteed to be immutable.
Modifier and Type | Field and Description |
---|---|
static Vector3D |
minusI
Opposite of the first canonical vector (coordinates: -1, 0, 0).
|
static Vector3D |
minusJ
Opposite of the second canonical vector (coordinates: 0, -1, 0).
|
static Vector3D |
minusK
Opposite of the third canonical vector (coordinates: 0, 0, -1).
|
static Vector3D |
plusI
First canonical vector (coordinates: 1, 0, 0).
|
static Vector3D |
plusJ
Second canonical vector (coordinates: 0, 1, 0).
|
static Vector3D |
plusK
Third canonical vector (coordinates: 0, 0, 1).
|
static Vector3D |
zero
Null vector (coordinates: 0, 0, 0).
|
Constructor and Description |
---|
Vector3D()
Simple constructor.
|
Vector3D(double alpha,
double delta)
Simple constructor.
|
Vector3D(double x,
double y,
double z)
Simple constructor.
|
Vector3D(double a,
Vector3D u)
Multiplicative constructor Build a vector from another one and a scale
factor.
|
Vector3D(double a1,
Vector3D u1,
double a2,
Vector3D u2)
Linear constructor Build a vector from two other ones and corresponding
scale factors.
|
Vector3D(double a1,
Vector3D u1,
double a2,
Vector3D u2,
double a3,
Vector3D u3)
Linear constructor Build a vector from three other ones and corresponding
scale factors.
|
Vector3D(double a1,
Vector3D u1,
double a2,
Vector3D u2,
double a3,
Vector3D u3,
double a4,
Vector3D u4)
Linear constructor Build a vector from four other ones and corresponding
scale factors.
|
Modifier and Type | Method and Description |
---|---|
Vector3D |
add(double factor,
Vector3D v)
Add a scaled vector to the instance.
|
Vector3D |
add(Vector3D v)
Add a vector to the instance.
|
static double |
angle(Vector3D v1,
Vector3D v2)
Compute the angular separation between two vectors.
|
static Vector3D |
crossProduct(Vector3D v1,
Vector3D v2)
Compute the cross-product of two vectors.
|
static double |
dotProduct(Vector3D v1,
Vector3D v2)
Compute the dot-product of two vectors.
|
double |
getAlpha()
Get the azimuth of the vector.
|
double |
getDelta()
Get the elevation of the vector.
|
double |
getNorm()
Get the norm for the vector.
|
double |
getX()
Get the abscissa of the vector.
|
double |
getY()
Get the ordinate of the vector.
|
double |
getZ()
Get the height of the vector.
|
Vector3D |
negate()
Get the opposite of the instance.
|
Vector3D |
normalize()
Get a normalized vector aligned with the instance.
|
Vector3D |
orthogonal()
Get a vector orthogonal to the instance.
|
Vector3D |
scalarMultiply(double a)
Multiply the instance by a scalar
|
Vector3D |
subtract(double factor,
Vector3D v)
Subtract a scaled vector from the instance.
|
Vector3D |
subtract(Vector3D v)
Subtract a vector from the instance.
|
public static final Vector3D plusI
public static final Vector3D minusI
public static final Vector3D plusJ
public static final Vector3D minusJ
public static final Vector3D plusK
public static final Vector3D minusK
public static final Vector3D zero
public Vector3D()
public Vector3D(double x, double y, double z)
public Vector3D(double alpha, double delta)
alpha
- azimuth (α) around Z (0 is +X, π/2 is +Y, π is -X
and 3π/2 is -Y)delta
- elevation (δ) above (XY) plane, from -π/2 to +π/2getAlpha()
,
getDelta()
public Vector3D(double a, Vector3D u)
a
- scale factoru
- base (unscaled) vectorpublic Vector3D(double a1, Vector3D u1, double a2, Vector3D u2)
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vectorpublic Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3)
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vectora3
- third scale factoru3
- third base (unscaled) vectorpublic Vector3D(double a1, Vector3D u1, double a2, Vector3D u2, double a3, Vector3D u3, double a4, Vector3D u4)
a1
- first scale factoru1
- first base (unscaled) vectora2
- second scale factoru2
- second base (unscaled) vectora3
- third scale factoru3
- third base (unscaled) vectora4
- fourth scale factoru4
- fourth base (unscaled) vectorpublic double getX()
Vector3D(double, double, double)
public double getY()
Vector3D(double, double, double)
public double getZ()
Vector3D(double, double, double)
public double getNorm()
public double getAlpha()
Vector3D(double, double)
public double getDelta()
Vector3D(double, double)
public Vector3D add(Vector3D v)
v
- vector to addpublic Vector3D add(double factor, Vector3D v)
factor
- scale factor to apply to v before adding itv
- vector to addpublic Vector3D subtract(Vector3D v)
v
- vector to subtractpublic Vector3D subtract(double factor, Vector3D v)
factor
- scale factor to apply to v before subtracting itv
- vector to subtractpublic Vector3D normalize()
java.lang.ArithmeticException
- if the norm is zeropublic Vector3D orthogonal()
There are an infinite number of normalized vectors orthogonal to the instance. This method picks up one of them almost arbitrarily. It is useful when one needs to compute a reference frame with one of the axes in a predefined direction. The following example shows how to build a frame having the k axis aligned with the known vector u :
<code> Vector3D k = u.normalize(); Vector3D i = k.orthogonal(); Vector3D j = Vector3D.crossProduct(k, i); </code>
java.lang.ArithmeticException
- if the norm of the instance is nullpublic static double angle(Vector3D v1, Vector3D v2)
This method computes the angular separation between two vectors using the dot product for well separated vectors and the cross product for almost aligned vectors. This allow to have a good accuracy in all cases, even for vectors very close to each other.
v1
- first vectorv2
- second vectorjava.lang.ArithmeticException
- if either vector has a null normpublic Vector3D negate()
public Vector3D scalarMultiply(double a)
a
- scalarpublic static double dotProduct(Vector3D v1, Vector3D v2)
v1
- first vectorv2
- second vectorprocessing library peasycam by Jonathan Feinberg. (c) 2013