Class Vector


  • public class Vector
    extends java.lang.Object
    Represents a vector (i.e. a point in space). This class is completely unrelated to the Vector class in the standard JRE.

    For many PDF related operations, the z coordinate is specified as 1 This is to support the coordinate transformation calculations. If it helps, just think of all PDF drawing operations as occurring in a single plane with z=1.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int I1
      index of the X coordinate
      private static int I2
      index of the Y coordinate
      private static int I3
      index of the Z coordinate
      private float[] values
      the values inside the vector
    • Constructor Summary

      Constructors 
      Constructor Description
      Vector​(float x, float y, float z)
      Creates a new Vector
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Vector add​(Vector v)
      Computes the sum of this vector and the specified vector
      Vector cross​(Matrix by)
      Computes the cross product of this vector and the specified matrix
      Vector cross​(Vector with)
      Computes the cross product of this vector and the specified vector
      float dot​(Vector with)
      Computes the dot product of this vector with the specified vector
      float get​(int index)
      Gets the value from a coordinate of the vector
      float length()
      Computes the length of this vector Note: If you are working with raw vectors from PDF, be careful - the Z axis will generally be set to 1.
      float lengthSquared()
      Computes the length squared of this vector.
      Vector subtract​(Vector v)
      Computes the difference between this vector and the specified vector
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • values

        private final float[] values
        the values inside the vector
    • Constructor Detail

      • Vector

        public Vector​(float x,
                      float y,
                      float z)
        Creates a new Vector
        Parameters:
        x - the X coordinate
        y - the Y coordinate
        z - the Z coordinate
    • Method Detail

      • get

        public float get​(int index)
        Gets the value from a coordinate of the vector
        Parameters:
        index - the index of the value to get (I1, I2 or I3)
        Returns:
        value from a coordinate of the vector
      • cross

        public Vector cross​(Matrix by)
        Computes the cross product of this vector and the specified matrix
        Parameters:
        by - the matrix to cross this vector with
        Returns:
        the result of the cross product
      • subtract

        public Vector subtract​(Vector v)
        Computes the difference between this vector and the specified vector
        Parameters:
        v - the vector to subtract from this one
        Returns:
        the results of the subtraction
      • add

        public Vector add​(Vector v)
        Computes the sum of this vector and the specified vector
        Parameters:
        v - the vector to subtract from this one
        Returns:
        the results of the subtraction
      • cross

        public Vector cross​(Vector with)
        Computes the cross product of this vector and the specified vector
        Parameters:
        with - the vector to cross this vector with
        Returns:
        the cross product
      • dot

        public float dot​(Vector with)
        Computes the dot product of this vector with the specified vector
        Parameters:
        with - the vector to dot product this vector with
        Returns:
        the dot product
      • length

        public float length()
        Computes the length of this vector Note: If you are working with raw vectors from PDF, be careful - the Z axis will generally be set to 1. If you want to compute the length of a vector, subtract it from the origin first (this will set the Z axis to 0).

        For example: aVector.subtract(originVector).length();

        Returns:
        the length of this vector
      • lengthSquared

        public float lengthSquared()
        Computes the length squared of this vector.

        The square of the length is less expensive to compute, and is often useful without taking the square root.

        Note: See the important note under length()

        Returns:
        the square of the length of the vector
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()