Class Orthonormal3DBasis

java.lang.Object
net.algart.math.geometry.Orthonormal3DBasis

public final class Orthonormal3DBasis extends Object

Right orthonormal basis in 3D 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 Details

  • Method Details

    • getSomeBasis

      public static Orthonormal3DBasis getSomeBasis(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). 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).
    • getBasis

      public static Orthonormal3DBasis getBasis(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), then behaviour depends on the argument exceptionOnCollinearity. If it is true, the method throws CollinearityException. In other case, the method ignores the passed vector (jx,jy,jz) and returns some basis according the passed vector (ix,iy,iz), like getSomeBasis(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.
    • getBasisOrNull

      public static Orthonormal3DBasis getBasisOrNull(double ix, double iy, double iz, double jx, double jy, double jz)
      Analogue of getBasis(ix, iy, iz, jx, jy, jz, true}, but instead of throwing exceptions this method just returns null.

      In other words, this method returns null 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 null when the passed two vectors are almost collinear. In all other cases, this method is equivalent to getBasis(double, double, double, double, double, double, boolean). 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 getBasis(double, double, double, double, double, double, boolean)).
    • getRandomBasis

      public static Orthonormal3DBasis getRandomBasis(Random random)
      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.
    • getRandomBasis

      public static Orthonormal3DBasis getRandomBasis(Random 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)
      Returns i * ix() + j * jx() + k * kx()
      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)
      Returns i * iy() + j * jy() + k * ky()
      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)
      Returns i * iz() + j * jz() + k * kz()
      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

      public Orthonormal3DBasis jki()
      Returns new basis (i', j', k'), where i'=j, j'=k, k'=i.
      Returns:
      new basis (j, k, i).
    • kij

      public Orthonormal3DBasis kij()
      Returns new basis (i', j', k'), where i'=k, j'=i, k'=j.
      Returns:
      new basis (k, i, j).
    • rotateJK

      public Orthonormal3DBasis rotateJK(double angleInRadians)
    • rotateKI

      public Orthonormal3DBasis rotateKI(double angleInRadians)
    • rotateIJ

      public Orthonormal3DBasis rotateIJ(double angleInRadians)
    • rotate

      public Orthonormal3DBasis rotate(double angleXYInRadians, double angleYZInRadians, double angleZXInRadians)
    • rotate

      public Orthonormal3DBasis rotate(double directionX, double directionY, double directionZ, double angle)
    • multiply

      public Orthonormal3DBasis multiply(Orthonormal3DBasis other)
    • inverse

      public Orthonormal3DBasis inverse()
    • distanceSquare

      public double distanceSquare(Orthonormal3DBasis other)
    • toString

      public String toString()
      Returns a brief string description of this object.

      The result of this method may depend on implementation.

      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.
    • equals

      public boolean equals(Object o)
      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 class Object
      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.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this object.
    • lengthSquare

      public static double lengthSquare(double x, double y, double z)