Class Vector3


  • public class Vector3
    extends java.lang.Object
    A Vector with 3 floats.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      float x  
      float y  
      float z  
    • Constructor Summary

      Constructors 
      Constructor Description
      Vector3()
      Construct a Vector3 and assign zero to all values
      Vector3​(float x, float y, float z)
      Construct a Vector3 and assign each value
      Vector3​(Vector3 v)
      Construct a Vector3 and copy the values
    • Field Detail

      • x

        public float x
      • y

        public float y
      • z

        public float z
    • Constructor Detail

      • Vector3

        public Vector3()
        Construct a Vector3 and assign zero to all values
      • Vector3

        public Vector3​(float x,
                       float y,
                       float z)
        Construct a Vector3 and assign each value
      • Vector3

        public Vector3​(Vector3 v)
        Construct a Vector3 and copy the values
    • Method Detail

      • set

        public void set​(Vector3 v)
        Copy the values from another Vector3 to this Vector3
      • set

        public void set​(float vx,
                        float vy,
                        float vz)
        Set each value
      • lengthSquared

        public float lengthSquared()
      • length

        public float length()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • normalized

        public Vector3 normalized()
        Scales the Vector3 to the unit length
      • scaled

        public Vector3 scaled​(float a)
        Uniformly scales a Vector3
        Returns:
        a Vector3 multiplied by a scalar amount
      • negated

        public Vector3 negated()
        Negates a Vector3
        Returns:
        A Vector3 with opposite direction
      • add

        public static Vector3 add​(Vector3 lhs,
                                  Vector3 rhs)
        Adds two Vector3's
        Returns:
        The combined Vector3
      • subtract

        public static Vector3 subtract​(Vector3 lhs,
                                       Vector3 rhs)
        Subtract two Vector3
        Returns:
        The combined Vector3
      • dot

        public static float dot​(Vector3 lhs,
                                Vector3 rhs)
        Get dot product of two Vector3's
        Returns:
        The scalar product of the Vector3's
      • cross

        public static Vector3 cross​(Vector3 lhs,
                                    Vector3 rhs)
        Get cross product of two Vector3's
        Returns:
        A Vector3 perpendicular to Vector3's
      • min

        public static Vector3 min​(Vector3 lhs,
                                  Vector3 rhs)
        Get a Vector3 with each value set to the element wise minimum of two Vector3's values
      • max

        public static Vector3 max​(Vector3 lhs,
                                  Vector3 rhs)
        Get a Vector3 with each value set to the element wise maximum of two Vector3's values
      • lerp

        public static Vector3 lerp​(Vector3 a,
                                   Vector3 b,
                                   float t)
        Linearly interpolates between a and b.
        Parameters:
        a - the beginning value
        b - the ending value
        t - ratio between the two floats.
        Returns:
        interpolated value between the two floats
      • angleBetweenVectors

        public static float angleBetweenVectors​(Vector3 a,
                                                Vector3 b)
        Returns the shortest angle in degrees between two vectors. The result is never greater than 180 degrees.
      • equals

        public static boolean equals​(Vector3 lhs,
                                     Vector3 rhs)
        Compares two Vector3's are equal if each component is equal within a tolerance.
      • equals

        public boolean equals​(java.lang.Object other)
        Returns true if the other object is a Vector3 and each component is equal within a tolerance.
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public static Vector3 zero()
        Gets a Vector3 with all values set to zero
      • one

        public static Vector3 one()
        Gets a Vector3 with all values set to one
      • forward

        public static Vector3 forward()
        Gets a Vector3 set to (0, 0, -1)
      • back

        public static Vector3 back()
        Gets a Vector3 set to (0, 0, 1)
      • up

        public static Vector3 up()
        Gets a Vector3 set to (0, 1, 0)
      • down

        public static Vector3 down()
        Gets a Vector3 set to (0, -1, 0)
      • right

        public static Vector3 right()
        Gets a Vector3 set to (1, 0, 0)
      • left

        public static Vector3 left()
        Gets a Vector3 set to (-1, 0, 0)