Class Orthonormal3DBasis
Right orthonormal basis in 3D Euclidean space: 3 orthogonal unit vectors i, j, k.
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
- Author:
- Daniel Alievsky
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
While creating a new basis, two vectors are considered to be "almost collinear" if the sine of the angle between them is less or aboutCOLLINEARITY_EPSILON
.static final double
The square ofCOLLINEARITY_EPSILON
.static final Orthonormal3DBasis
Default basis: I=(1,0,0), J=(0,1,0), K=(0,0,1).static final double
Minimal allowed length of the vectors (ix,iy,iz) and (jx,jy,jz), passed to creation methodsnewBasis(double, double, double, double, double, double, boolean)
,newSomeBasis(double, double, double)
. -
Method Summary
Modifier and TypeMethodDescriptiondouble
distanceSquare
(Orthonormal3DBasis other) boolean
Indicates whether some other object is an instance of this class, representing the same basis.int
hashCode()
Returns the hash code of this object.inverse()
double
ix()
Returns x-component of i vector.double
iy()
Returns y-component of i vector.double
iz()
Returns z-component of i vector.jki()
Returns new basis (i', j', k'), where i'=j, j'=k, k'=i.double
jx()
Returns x-component of j vector.double
jy()
Returns y-component of j vector.double
jz()
Returns z-component of j vector.kij()
Returns new basis (i', j', k'), where i'=k, j'=i, k'=j.double
kx()
Returns x-component of k vector.double
ky()
Returns y-component of j vector.double
kz()
Returns z-component of j vector.static double
length
(double x, double y, double z) Returns the length of 3D segment with the given projections to the axes.static double
lengthSquare
(double x, double y, double z) Returns the square of the length of 3D segment with the given projections to the axes.multiply
(Orthonormal3DBasis other) static Orthonormal3DBasis
newBasis
(double ix, double iy, double iz, double jx, double jy, double jz, boolean exceptionOnCollinearity) Creates new basis, where i vector has components (ix/d1, iy/d1, iz/d1), d1=sqrt(ix2+iy2+iz2), j vector has components (jx/d2, jy/d2, jz/d2), d2=sqrt(jx2+jy2+jz2), k vector is chosen automatically to provide right orthonormal basis.static Orthonormal3DBasis
newRandomBasis
(RandomGenerator random) Creates a pseudorandom basis, which orientation is uniformly distributed in the space.static Orthonormal3DBasis
newRandomBasis
(RandomGenerator random, double ix, double iy, double iz) Creates a pseudorandom basis, where i vector has components (ix/d, iy/d, iz/d), d=sqrt(ix2+iy2+iz2).static Orthonormal3DBasis
newSomeBasis
(double ix, double iy, double iz) Creates new basis, where i vector has components (ix/d, iy/d, iz/d), d=sqrt(ix2+iy2+iz2).static Optional<Orthonormal3DBasis>
optBasis
(double ix, double iy, double iz, double jx, double jy, double jz) Analogue ofgetBasis(ix, iy, iz, jx, jy, jz, true
}, but instead of throwing exceptions this method just returns Optional.empty().rotate
(double angleXYInRadians, double angleYZInRadians, double angleZXInRadians) rotate
(double directionX, double directionY, double directionZ, double angle) rotateIJ
(double angleInRadians) rotateJK
(double angleInRadians) rotateKI
(double angleInRadians) static double
scalarProduct
(double ax, double ay, double az, double bx, double by, double bz) Returns the scalar product of a and b vectors: ax * bx + ay * by + az * bz.toString()
Returns a brief string description of this object.double
x
(double i, double j, double k) double
y
(double i, double j, double k) double
z
(double i, double j, double k)
-
Field Details
-
COLLINEARITY_EPSILON
public static final double COLLINEARITY_EPSILONWhile creating a new basis, two vectors are considered to be "almost collinear" if the sine of the angle between them is less or aboutCOLLINEARITY_EPSILON
.- See Also:
-
COLLINEARITY_EPSILON_SQR
public static final double COLLINEARITY_EPSILON_SQRThe square ofCOLLINEARITY_EPSILON
.- See Also:
-
MIN_ALLOWED_LENGTH
public static final double MIN_ALLOWED_LENGTHMinimal allowed length of the vectors (ix,iy,iz) and (jx,jy,jz), passed to creation methodsnewBasis(double, double, double, double, double, double, boolean)
,newSomeBasis(double, double, double)
.- See Also:
-
DEFAULT
Default basis: I=(1,0,0), J=(0,1,0), K=(0,0,1).
-
-
Method Details
-
newSomeBasis
Creates new basis, where i vector has components (ix/d, iy/d, iz/d), d=sqrt(ix2+iy2+iz2). Other vectors j and k will have some values, depending on the implementation.- Parameters:
ix
- x-component of new i vector (maybe, multiplied by some d constant).iy
- y-component of new i vector (maybe, multiplied by some d constant).iz
- z-component of new i vector (maybe, multiplied by some d constant).- Returns:
- new right orthonormal basis with given direction of i vector.
- Throws:
IllegalArgumentException
- if the length sqrt(ix2+iy2+iz2) of the passed vector (ix,iy,iz) is zero or too small (<MIN_ALLOWED_LENGTH
).
-
newBasis
public static Orthonormal3DBasis newBasis(double ix, double iy, double iz, double jx, double jy, double jz, boolean exceptionOnCollinearity) throws CollinearityException Creates new basis, where i vector has components (ix/d1, iy/d1, iz/d1), d1=sqrt(ix2+iy2+iz2), j vector has components (jx/d2, jy/d2, jz/d2), d2=sqrt(jx2+jy2+jz2), k vector is chosen automatically to provide right orthonormal basis.If the passed vectors (ix,iy,iz) and (jx,jy,jz) are not orthogonal, the vector (jx,jy,jz) is automatically corrected, before all other calculations, to become orthogonal to i, and the plane ij is preserved while this correction.
If the passed vectors are collinear or almost collinear (with very little angle difference, about 10−8..10−6 radians or something like this), or if the length of one of the passed vectors is less than
MIN_ALLOWED_LENGTH
, then behaviour depends on exceptionOnCollinearity argument. If it is true, the method throwsCollinearityException
. In other case, the method ignores the passed vector (jx,jy,jz) and returns some basis according the passed vector (ix,iy,iz), asnewSomeBasis(double, double, double)
method.- Parameters:
ix
- x-component of new i vector (maybe, multiplied by some d1 constant).iy
- y-component of new i vector (maybe, multiplied by some d1 constant).iz
- z-component of new i vector (maybe, multiplied by some d1 constant).jx
- x-component of new j vector (maybe, multiplied by some d2 constant).jy
- y-component of new j vector (maybe, multiplied by some d2 constant).jz
- z-component of new j vector (maybe, multiplied by some d2 constant).exceptionOnCollinearity
- whether exception is thrown for collinear vector pair.- Returns:
- new right orthonormal basis with given direction of i vector and the direction of j vector, chosen according the arguments (see above).
- Throws:
IllegalArgumentException
- if the length sqrt(ix2+iy2+iz2) of the passed vector (ix,iy,iz) or the length sqrt(jx2+jy2+jz2) of the passed vector (jx,jy,jz) is zero or too small (<MIN_ALLOWED_LENGTH
).CollinearityException
- if the passed two vectors are almost collinear and exceptionOnCollinearity==true.
-
optBasis
public static Optional<Orthonormal3DBasis> optBasis(double ix, double iy, double iz, double jx, double jy, double jz) Analogue ofgetBasis(ix, iy, iz, jx, jy, jz, true
}, but instead of throwing exceptions this method just returns Optional.empty().In other words, this method returns Optional.empty() when the length sqrt(ix2+iy2+iz2) of the passed vector (ix,iy,iz) or the length sqrt(jx2+jy2+jz2) of the passed vector (jx,jy,jz) is zero or too small (<
MIN_ALLOWED_LENGTH
), and also this method returns Optional.empty() when the passed two vectors are almost collinear. In all other cases, this method is equivalent to Optional.of(getBasis(ix, iy, iz, jx, jy, jz, true/false)
) (the last argument is not important). This method never throws any exceptions.- Parameters:
ix
- x-component of new i vector (maybe, multiplied by some d1 constant).iy
- y-component of new i vector (maybe, multiplied by some d1 constant).iz
- z-component of new i vector (maybe, multiplied by some d1 constant).jx
- x-component of new j vector (maybe, multiplied by some d2 constant).jy
- y-component of new j vector (maybe, multiplied by some d2 constant).jz
- z-component of new j vector (maybe, multiplied by some d2 constant).- Returns:
- new right orthonormal basis with given direction of i vector
and the direction of j vector, chosen according the arguments
(see
newBasis(double, double, double, double, double, double, boolean)
), or empty value in a case of problems.
-
newRandomBasis
Creates a pseudorandom basis, which orientation is uniformly distributed in the space. The orientation is chosen with help of random.nextDouble() method.- Parameters:
random
- random generator used to create the basis.- Returns:
- new right orthonormal basis with random orientation.
-
newRandomBasis
public static Orthonormal3DBasis newRandomBasis(RandomGenerator random, double ix, double iy, double iz) Creates a pseudorandom basis, where i vector has components (ix/d, iy/d, iz/d), d=sqrt(ix2+iy2+iz2). Directions of vector pair j, k are uniformly distributed in the plane, perpendicular to i vector. These directions are chosen with help of random.nextDouble() method.- Parameters:
random
- random generator used to create the basis.ix
- x-component of new i vector (maybe, multiplied by some d constant).iy
- y-component of new i vector (maybe, multiplied by some d constant).iz
- z-component of new i vector (maybe, multiplied by some d constant).- Returns:
- new randomly oriented right orthonormal basis with given direction of i vector.
- Throws:
IllegalArgumentException
- if the length sqrt(ix2+iy2+iz2) of the passed vector (ix,iy,iz) is zero or too small (<MIN_ALLOWED_LENGTH
).
-
ix
public double ix()Returns x-component of i vector.- Returns:
- x-component of i vector.
-
iy
public double iy()Returns y-component of i vector.- Returns:
- y-component of i vector.
-
iz
public double iz()Returns z-component of i vector.- Returns:
- z-component of i vector.
-
jx
public double jx()Returns x-component of j vector.- Returns:
- x-component of j vector.
-
jy
public double jy()Returns y-component of j vector.- Returns:
- y-component of j vector.
-
jz
public double jz()Returns z-component of j vector.- Returns:
- z-component of j vector.
-
kx
public double kx()Returns x-component of k vector.- Returns:
- x-component of k vector.
-
ky
public double ky()Returns y-component of j vector.- Returns:
- y-component of j vector.
-
kz
public double kz()Returns z-component of j vector.- Returns:
- z-component of j vector.
-
x
public double x(double i, double j, double k) - Parameters:
i
- projection of some vector p to the basis vector i.j
- projection of some vector p to the basis vector j.k
- projection of some vector p to the basis vector k.- Returns:
- x-component of such p vector.
-
y
public double y(double i, double j, double k) - Parameters:
i
- projection of some vector p to the basis vector i.j
- projection of some vector p to the basis vector j.k
- projection of some vector p to the basis vector k.- Returns:
- y-component of such p vector.
-
z
public double z(double i, double j, double k) - Parameters:
i
- projection of some vector p to the basis vector i.j
- projection of some vector p to the basis vector j.k
- projection of some vector p to the basis vector k.- Returns:
- z-component of such p vector.
-
jki
Returns new basis (i', j', k'), where i'=j, j'=k, k'=i.- Returns:
- new basis (j, k, i).
-
kij
Returns new basis (i', j', k'), where i'=k, j'=i, k'=j.- Returns:
- new basis (k, i, j).
-
rotateJK
-
rotateKI
-
rotateIJ
-
rotate
public Orthonormal3DBasis rotate(double angleXYInRadians, double angleYZInRadians, double angleZXInRadians) -
rotate
public Orthonormal3DBasis rotate(double directionX, double directionY, double directionZ, double angle) -
multiply
-
inverse
-
distanceSquare
-
toString
Returns a brief string description of this object.The result of this method may depend on implementation.
-
equals
Indicates whether some other object is an instance of this class, representing the same basis. The corresponding coordinates of vectors are compared as in Double.equals method, i.e. they are converted to long values by Double.doubleToLongBits method and the results are compared.- Overrides:
equals
in classObject
- Parameters:
o
- the object to be compared for equality with this instance.- Returns:
- true if and only if the specified object is an instance of
Orthonormal3DBasis
, representing the same right orthonormal basis as this object.
-
hashCode
public int hashCode()Returns the hash code of this object. -
lengthSquare
public static double lengthSquare(double x, double y, double z) Returns the square of the length of 3D segment with the given projections to the axes. Equivalent to x * x + y * y + z * z.- Parameters:
x
- x-projection of the segment.y
- y-projection of the segment.z
- z-projection of the segment.- Returns:
- the square of the segment length.
-
length
public static double length(double x, double y, double z) Returns the length of 3D segment with the given projections to the axes. Equivalent to Math.sqrt(lengthSquare
(x, y, z))..- Parameters:
x
- x-projection of the segment.y
- y-projection of the segment.z
- z-projection of the segment.- Returns:
- the segment length.
-
scalarProduct
public static double scalarProduct(double ax, double ay, double az, double bx, double by, double bz) Returns the scalar product of a and b vectors: ax * bx + ay * by + az * bz.- Parameters:
ax
- x-component of the vector a.ay
- y-component of the vector a.az
- z-component of the vector a.bx
- x-component of the vector b.by
- y-component of the vector b.bz
- z-component of the vector b.- Returns:
- scalar product of two vectors.
-