Documentation of 'org.spaceroots.mantissa.geometry.Vector3D' Java class
Vector3D
org.spaceroots.mantissa.geometry

Class Vector3D

  • All Implemented Interfaces:
    java.io.Serializable


    public class Vector3D
    extends java.lang.Object
    implements java.io.Serializable
    This class implements vectors in a three-dimensional space.

    Instance of this class are guaranteed to be immutable.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      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).
    • Constructor Summary

      Constructors 
      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.
    • Field Detail

      • plusI

        public static final Vector3D plusI
        First canonical vector (coordinates : 1, 0, 0).
      • minusI

        public static final Vector3D minusI
        Opposite of the first canonical vector (coordinates : -1, 0, 0).
      • plusJ

        public static final Vector3D plusJ
        Second canonical vector (coordinates : 0, 1, 0).
      • minusJ

        public static final Vector3D minusJ
        Opposite of the second canonical vector (coordinates : 0, -1, 0).
      • plusK

        public static final Vector3D plusK
        Third canonical vector (coordinates : 0, 0, 1).
      • minusK

        public static final Vector3D minusK
        Opposite of the third canonical vector (coordinates : 0, 0, -1).
    • Constructor Detail

      • Vector3D

        public Vector3D()
        Simple constructor. Build a null vector.
      • Vector3D

        public Vector3D(double x,
                        double y,
                        double z)
        Simple constructor. Build a vector from its coordinates
        Parameters:
        x - abscissa
        y - ordinate
        z - height
        See Also:
        getX(), getY(), getZ()
      • Vector3D

        public Vector3D(double alpha,
                        double delta)
        Simple constructor. Build a vector from its azimuthal coordinates
        Parameters:
        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 +π/2
        See Also:
        getAlpha(), getDelta()
      • Vector3D

        public Vector3D(double a,
                        Vector3D u)
        Multiplicative constructor Build a vector from another one and a scale factor. The vector built will be a * u
        Parameters:
        a - scale factor
        u - base (unscaled) vector
      • Vector3D

        public Vector3D(double a1,
                        Vector3D u1,
                        double a2,
                        Vector3D u2)
        Linear constructor Build a vector from two other ones and corresponding scale factors. The vector built will be a1 * u1 + a2 * u2
        Parameters:
        a1 - first scale factor
        u1 - first base (unscaled) vector
        a2 - second scale factor
        u2 - second base (unscaled) vector
      • Vector3D

        public 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. The vector built will be a1 * u1 + a2 * u2 + a3 * u3
        Parameters:
        a1 - first scale factor
        u1 - first base (unscaled) vector
        a2 - second scale factor
        u2 - second base (unscaled) vector
        a3 - third scale factor
        u3 - third base (unscaled) vector
      • Vector3D

        public 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. The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
        Parameters:
        a1 - first scale factor
        u1 - first base (unscaled) vector
        a2 - second scale factor
        u2 - second base (unscaled) vector
        a3 - third scale factor
        u3 - third base (unscaled) vector
        a4 - fourth scale factor
        u4 - fourth base (unscaled) vector
    • Method Detail

      • getNorm

        public double getNorm()
        Get the norm for the vector.
        Returns:
        euclidian norm for the vector
      • getAlpha

        public double getAlpha()
        Get the azimuth of the vector.
        Returns:
        azimuth (α) of the vector, between -π and +π
        See Also:
        Vector3D(double, double)
      • getDelta

        public double getDelta()
        Get the elevation of the vector.
        Returns:
        elevation (δ) of the vector, between -π/2 and +π/2
        See Also:
        Vector3D(double, double)
      • add

        public Vector3D add(Vector3D v)
        Add a vector to the instance.
        Parameters:
        v - vector to add
        Returns:
        a new vector
      • add

        public Vector3D add(double factor,
                            Vector3D v)
        Add a scaled vector to the instance.
        Parameters:
        factor - scale factor to apply to v before adding it
        v - vector to add
        Returns:
        a new vector
      • subtract

        public Vector3D subtract(Vector3D v)
        Subtract a vector from the instance.
        Parameters:
        v - vector to subtract
        Returns:
        a new vector
      • subtract

        public Vector3D subtract(double factor,
                                 Vector3D v)
        Subtract a scaled vector from the instance.
        Parameters:
        factor - scale factor to apply to v before subtracting it
        v - vector to subtract
        Returns:
        a new vector
      • normalize

        public Vector3D normalize()
        Normalize the instance.
        Returns:
        a new normalized vector
        Throws:
        java.lang.ArithmeticException - if the norm is null
      • orthogonal

        public Vector3D orthogonal()
        Get a vector orthogonal to the instance.

        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 :

        
           Vector3D k = u.normalize();
           Vector3D i = k.orthogonal();
           Vector3D j = Vector3D.crossProduct(k, i);
         

        Returns:
        a new normalized vector orthogonal to the instance
        Throws:
        java.lang.ArithmeticException - if the norm of the instance is null
      • angle

        public static double angle(Vector3D v1,
                                   Vector3D v2)
        Compute the angular separation between two vectors.

        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.

        Parameters:
        v1 - first vector
        v2 - second vector
        Throws:
        java.lang.ArithmeticException - if either vector has a null norm
      • negate

        public Vector3D negate()
        Get the opposite of the instance.
        Returns:
        a new vector which is opposite to the instance
      • multiply

        public Vector3D multiply(double a)
        Multiply the instance by a scalar
        Parameters:
        a - scalar
        Returns:
        a new vector
      • dotProduct

        public static double dotProduct(Vector3D v1,
                                        Vector3D v2)
        Compute the dot-product of two vectors.
        Parameters:
        v1 - first vector
        v2 - second vector
        Returns:
        the dot product v1.v2
      • crossProduct

        public static Vector3D crossProduct(Vector3D v1,
                                            Vector3D v2)
        Compute the cross-product of two vectors.
        Parameters:
        v1 - first vector
        v2 - second vector
        Returns:
        the cross product v1 ^ v2 as a new Vector

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.