Class Vector3f

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Vector3f>

    public class Vector3f
    extends java.lang.Object
    implements java.lang.Comparable<Vector3f>, java.io.Serializable
    3D Vector object.
    See Also:
    Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Serialization support
        See Also:
        Constant Field Values
      • ZERO

        public static final transient Vector3f ZERO
        Zero vector: (0,0,0)
      • UNIT_X

        public static final transient Vector3f UNIT_X
        Unit-X vector: (1,0,0)
      • UNIT_Y

        public static final transient Vector3f UNIT_Y
        Unit-Y vector: (0,1,0)
      • UNIT_Z

        public static final transient Vector3f UNIT_Z
        Unit-Z vector: (0,0,1)
      • UNIT_X_NEG

        public static final transient Vector3f UNIT_X_NEG
        negative unit-X vector: (-1,0,0)
      • UNIT_Y_NEG

        public static final transient Vector3f UNIT_Y_NEG
        negative unit-Y vector: (0,-1,0)
      • UNIT_Z_NEG

        public static final transient Vector3f UNIT_Z_NEG
        negative unit-Z vector: (0,0,-1)
      • ONE

        public static final transient Vector3f ONE
        One vector: (1,1,1)
      • X

        public float X
        Vector data:
      • Y

        public float Y
      • Z

        public float Z
    • Constructor Detail

      • Vector3f

        public Vector3f()
        construction, initialized to (0,0,0)
      • Vector3f

        public Vector3f​(float fX,
                        float fY,
                        float fZ)
        construction
        Parameters:
        fX - x-value
        fY - y-value
        fZ - z-value
      • Vector3f

        public Vector3f​(float[] afTuple)
        construction
        Parameters:
        afTuple - x,y,z values
      • Vector3f

        public Vector3f​(Vector3f rkV)
        copy construction
        Parameters:
        rkV - vector to copy.
    • Method Detail

      • angle

        public static float angle​(Vector3f rkV1,
                                  Vector3f rkV2)
        Parameters:
        rkV1 -
        rkV2 -
        Returns:
      • computeExtremes

        public static void computeExtremes​(int iVQuantity,
                                           Vector3f[] akPoint,
                                           Vector3f rkMin,
                                           Vector3f rkMax)
        Computes the extremes: min, max for x,y,z from an array of Vector3f.
        Parameters:
        iVQuantity - the number of Vector3f in the array
        akPoint - the array of Vector3f to compute the extremes for.
        rkMin - set to minimum (x,y,z) of all the Vectors in the array.
        rkMax - set to maximum (x,y,z) of all the Vectors in the array.
      • generateComplementBasis

        public static void generateComplementBasis​(Vector3f rkU,
                                                   Vector3f rkV,
                                                   Vector3f rkW)
        Input W must be a unit-length vector. The output vectors {U,V} are unit length and mutually perpendicular, and {U,V,W} is an orthonormal basis.
        Parameters:
        rkU - U
        rkV - V
        rkW - W, input and output
      • generateOrthonormalBasis

        public static void generateOrthonormalBasis​(Vector3f rkU,
                                                    Vector3f rkV,
                                                    Vector3f rkW)
        Input W must be a nonzero vector. The output is an orthonormal basis {U,V,W}. The input W is normalized by this function. If you know W is already unit length, use GenerateComplementBasis to compute U and V.
        Parameters:
        rkU - U
        rkV - V
        rkW - W, input and output
      • add

        public Vector3f add​(float fX,
                            float fY,
                            float fZ)
        Add the inputs to this, this = this + fX,fY,fZ
        Parameters:
        fX - x-value
        fY - y-value
        fZ - z-value
      • add

        public Vector3f add​(Vector3f rkV)
        Add the input vector to this: this = this + rkV
        Parameters:
        rkV -
        Returns:
        this
      • add

        public static Vector3f add​(Vector3f rkV1,
                                   Vector3f rkV2)
        Add the two input vectors, setting this: this = rkV1 + rkV2
        Parameters:
        rkV1 - first input vector
        rkV2 - second input vector
      • angle

        public float angle​(Vector3f rkV1)
      • copy

        public Vector3f copy​(Vector3f rkV)
        copy into this vector.
        Parameters:
        rkV - vector to copy.
      • cross

        public Vector3f cross​(Vector3f rkV)
        The cross products are computed using the right-handed rule. Be aware that some graphics APIs use a left-handed rule. If you have to compute a cross product with these functions and send the result to the API that expects left-handed, you will need to change sign on the vector (replace each component value c by -c). this = this ^ kV
        Parameters:
        rkV - vector to cross with this
      • cross

        public static Vector3f cross​(Vector3f kV1,
                                     Vector3f kV2)
        The cross products are computed using the right-handed rule. Be aware that some graphics APIs use a left-handed rule. If you have to compute a cross product with these functions and send the result to the API that expects left-handed, you will need to change sign on the vector (replace each component value c by -c). this = kV1 ^ kV2
        Parameters:
        kV1 - first vector
        kV2 - second vector
      • distance

        public float distance​(Vector3f kV)
        Compute the distance from this vector to the input vector.
        Parameters:
        kV - vector to calculate distance to.
        Returns:
        distance from this vector to the input vector.
      • div

        public Vector3f div​(float fScalar)
        Divide this vector by fScalar: this = this/fScalar
        Parameters:
        fScalar - scale value
      • div

        public static Vector3f div​(float fScalar,
                                   Vector3f kV)
        Divide the vector by fScalar, setting this: this = kV/fScalar
        Parameters:
        fScalar - scale value
        kV - input vector
      • dot

        public float dot​(Vector3f rkV)
        Compute dot-product of this vector with input vector:
        Returns:
        dot-product of this vector with input vector:
      • equals

        public boolean equals​(java.lang.Object kObject)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • invert

        public Vector3f invert()
        Invert this vector: this = 1/this;
      • isEqual

        public boolean isEqual​(Vector3f rkV)
        Return true if the input Vector3f is equal to this.
        Parameters:
        rkV - input vector to compare to this
        Returns:
        true if the input Vector3f is equal to this, false otherwise.
      • isLessThan

        public boolean isLessThan​(Vector3f rkV)
        Return true if the input Vector3f is less than to this.
        Parameters:
        rkV - input vector to compare to this
        Returns:
        true if the input Vector3f is less than to this, false otherwise.
      • length

        public float length()
        Compute length this vector:
        Returns:
        length this vector
      • max

        public Vector3f max​(Vector3f kV)
        Maximum function. Sets this to be the maximum of this and the input vector: this = max( this, kV ).
        Parameters:
        kV - input vector.
      • min

        public Vector3f min​(Vector3f kV)
        Minimum function. Sets this to be the minimum of this and the input vector: this = min( this, kV ).
        Parameters:
        kV - input vector.
      • mult

        public Vector3f mult​(Vector3f rkV)
        Multiply the input vector to this: this = this * rkV
        Parameters:
        rkV - input vector to multiply to this
      • mult

        public static Vector3f mult​(Vector3f rkV1,
                                    Vector3f rkV2)
        Multiply the two input vectors, setting this: this = rkV1 * rkV2
        Parameters:
        rkV1 - first input vector
        rkV2 - second input vector
      • neg

        public Vector3f neg()
        Negate this vector: this = - this.
      • neg

        public static Vector3f neg​(Vector3f kV)
        Set this to the negative of the input vector: this = -kV.
        Parameters:
        kV - input vector.
      • normalize

        public float normalize()
        Normalize this vector, return original length:
        Returns:
        original length:
      • normalize

        public static float normalize​(Vector3f kV)
        Normalize this vector, return original length:
        Returns:
        original length:
      • scale

        public Vector3f scale​(float fScalar)
        this = this * fScalar
        Parameters:
        fScalar -
        Returns:
        this
      • scale

        public Vector3f scale​(float fX,
                              float fY,
                              float fZ)
        Scale this vector by input: this = this * fScalar.
        Parameters:
        fX - scale X value
        fY - scale Y value
        fZ - scale Z value
      • scale

        public static Vector3f scale​(float fScalar,
                                     Vector3f rkV)
        Parameters:
        fScalar -
        rkV -
        Returns:
        fScalar * rkV
      • scaleAdd

        public Vector3f scaleAdd​(float fScalar,
                                 Vector3f rkV1,
                                 Vector3f rkV2)
        Scale the input vector by the scalar, setting this: this = fScalar * rkV1 + rkV2.
        Parameters:
        fScalar - scale value
        rkV1 - input vector
        rkV2 - input vector
      • set

        public Vector3f set​(float fX,
                            float fY,
                            float fZ)
        construction
        Parameters:
        fX - x-value
        fY - y-value
        fZ - z-value
      • squaredDistance

        public float squaredDistance​(Vector3f kV)
        Compute the distance from this vector to the input vector.
        Parameters:
        kV - vector to calculate distance to.
        Returns:
        distance from this vector to the input vector.
      • squaredLength

        public float squaredLength()
        Compute squared-length this vector:
        Returns:
        squared-length this vector
      • squaredRootLength

        public float squaredRootLength()
      • sub

        public Vector3f sub​(Vector3f rkV)
        this = this - rkV
        Parameters:
        rkV -
        Returns:
        this
      • sub

        public static Vector3f sub​(Vector3f rkV1,
                                   Vector3f rkV2)
        Subtract the two input vectors, setting this: this = rkV1 - rkV2
        Parameters:
        rkV1 - first input vector
        rkV2 - second input vector
      • sum

        public float sum()
        Sum the elements of the vector.
        Returns:
        vector sum
      • toString

        public java.lang.String toString()
        Returns a string representation of the vector values.
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of the vector values.
      • unitCross

        public Vector3f unitCross​(Vector3f rkV)
        The cross products are computed using the right-handed rule. Be aware that some graphics APIs use a left-handed rule. If you have to compute a cross product with these functions and send the result to the API that expects left-handed, you will need to change sign on the vector (replace each component value c by -c). this = this ^ kV Normalize(this)
        Parameters:
        rkV - vector to cross with this
      • unitCross

        public static Vector3f unitCross​(Vector3f kV1,
                                         Vector3f kV2)
        The cross products are computed using the right-handed rule. Be aware that some graphics APIs use a left-handed rule. If you have to compute a cross product with these functions and send the result to the API that expects left-handed, you will need to change sign on the vector (replace each component value c by -c). this = kV1 ^ kV2 Normalize(this)
        Parameters:
        kV1 - first vector
        kV2 - second vector
      • compare

        public int compare​(Vector3f arg0,
                           Vector3f arg1)
        Sorting a list of Vector3f in order, where each element is a column when two Vector3f have equal X then the sort is by Y, then by Z.
        Parameters:
        arg0 -
        arg1 -
        Returns:
      • compareTo

        public int compareTo​(Vector3f v)
        Specified by:
        compareTo in interface java.lang.Comparable<Vector3f>