Class Vector3

java.lang.Object
icyllis.arc3d.core.Vector3

public class Vector3 extends Object
Represents a three-dimensional vector.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
     
    float
     
    float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a zero vector
    Vector3(float x, float y, float z)
    Create a vector with given components.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add each component of a vector to this vector.
     
    void
    cross(float x, float y, float z)
    Cross product of this vector with the given x, y and z components.
    void
    Cross product of this vector with the given vector.
    float
    dot(float x, float y, float z)
    Returns the dot product of this vector with the given x, y and z components.
    float
    Returns the dot product of this vector with the given vector.
    boolean
     
    boolean
    Returns whether this vector is equivalent to given vector.
    int
     
    boolean
    Returns whether this vector is normalized.
    float
    Returns the magnitude of this vector, namely the 2-norm (euclidean norm) or the length.
    float
     
    void
    Calculate component-wise maximum of this and the given vector.
    void
    Calculate component-wise minimum of this and the given vector.
    void
    multiply(float s)
    Multiply this vector by a factor.
    void
    multiply(float mx, float my, float mz)
    Multiply each component of the vector by given multipliers
    void
    Multiply each component of the vector by the given vector.
    void
    Negate this vector [-x, -y, -z].
    void
    Normalize this vector to unit length, or [1, 0, 0] if this is zero.
    void
    Calculate an arbitrary unit vector perpendicular to this, this vector must be normalized.
    void
    Pre-transform this vector by a 4x4 transformation matrix.
    float
    Returns the product of all the vector components.
    void
    Calculate the projection of the vector on the given vector.
    void
    Reverse the order of components.
    rotation(float angle)
    Create a rotational quaternion clockwise about this axis with given angle in radians.
    void
    set(float x, float y, float z)
    Set all values of this vector using the given components.
    void
    Set all values of this vector using the given vector.
    void
    Set all values of this vector to zero.
    void
    Sort components of this in ascending order.
    void
    Subtract each component of a vector from this vector.
    float
    sum()
    Returns the sum of all the vector components.
     
    void
    Transform this vector by a 4x4 transformation matrix.
    void
    Transform this vector by a quaternion rotation.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public float x
    • y

      public float y
    • z

      public float z
  • Constructor Details

    • Vector3

      public Vector3()
      Create a zero vector
    • Vector3

      public Vector3(float x, float y, float z)
      Create a vector with given components.
      Parameters:
      x - the x-component of the vector
      y - the y-component of the vector
      z - the z-component of the vector
  • Method Details

    • set

      public void set(float x, float y, float z)
      Set all values of this vector using the given components.
      Parameters:
      x - the x-component to set
      y - the y-component to set
      z - the z-component to set
    • set

      public void set(@Nonnull Vector3 v)
      Set all values of this vector using the given vector.
      Parameters:
      v - the vector to copy from
    • add

      public void add(@Nonnull Vector3 v)
      Add each component of a vector to this vector.
      Parameters:
      v - the vector to add
    • subtract

      public void subtract(@Nonnull Vector3 v)
      Subtract each component of a vector from this vector.
      Parameters:
      v - the vector to subtract
    • multiply

      public void multiply(float s)
      Multiply this vector by a factor.
      Parameters:
      s - the factor to multiply.
    • multiply

      public void multiply(float mx, float my, float mz)
      Multiply each component of the vector by given multipliers
      Parameters:
      mx - the x-component multiplier
      my - the y-component multiplier
      mz - the z-component multiplier
    • multiply

      public void multiply(@Nonnull Vector3 v)
      Multiply each component of the vector by the given vector.
      Parameters:
      v - the vector to multiply with
    • length

      public float length()
      Returns the magnitude of this vector, namely the 2-norm (euclidean norm) or the length.
      Returns:
      the magnitude of this quaternion
    • lengthSq

      public float lengthSq()
    • dot

      public float dot(float x, float y, float z)
      Returns the dot product of this vector with the given x, y and z components.
    • dot

      public float dot(@Nonnull Vector3 v)
      Returns the dot product of this vector with the given vector.
      Parameters:
      v - the vector to dot product with.
    • cross

      public void cross(float x, float y, float z)
      Cross product of this vector with the given x, y and z components.
    • cross

      public void cross(@Nonnull Vector3 v)
      Cross product of this vector with the given vector.
      Parameters:
      v - the vector to cross product with.
    • minComponent

      public void minComponent(@Nonnull Vector3 v)
      Calculate component-wise minimum of this and the given vector.
    • maxComponent

      public void maxComponent(@Nonnull Vector3 v)
      Calculate component-wise maximum of this and the given vector.
    • isNormalized

      public boolean isNormalized()
      Returns whether this vector is normalized.
      Returns:
      true if is normalized, false otherwise
    • normalize

      public void normalize()
      Normalize this vector to unit length, or [1, 0, 0] if this is zero.
    • setZero

      public void setZero()
      Set all values of this vector to zero.
    • negate

      public void negate()
      Negate this vector [-x, -y, -z].
    • sum

      public float sum()
      Returns the sum of all the vector components.
      Returns:
      the sum of all the vector components
    • product

      public float product()
      Returns the product of all the vector components.
      Returns:
      the product of all the vector components
    • perpendicular

      public void perpendicular()
      Calculate an arbitrary unit vector perpendicular to this, this vector must be normalized.
    • projection

      public void projection(@Nonnull Vector3 v)
      Calculate the projection of the vector on the given vector.
      Parameters:
      v - the vector to project on
    • rotation

      @Nonnull public Quaternion rotation(float angle)
      Create a rotational quaternion clockwise about this axis with given angle in radians. This vector must be normalized.
      Parameters:
      angle - rotation angle in radians
      Returns:
      a quaternion represents the rotation
    • transform

      public void transform(@Nonnull Matrix4 mat)
      Transform this vector by a 4x4 transformation matrix.
      Parameters:
      mat - the matrix to transform from
    • preTransform

      public void preTransform(@Nonnull Matrix4 mat)
      Pre-transform this vector by a 4x4 transformation matrix.
      Parameters:
      mat - the matrix to transform from
    • transform

      public void transform(@Nonnull Quaternion q)
      Transform this vector by a quaternion rotation.
      Parameters:
      q - the quaternion to rotate the vector by
    • sort

      public void sort()
      Sort components of this in ascending order.
    • reverse

      public void reverse()
      Reverse the order of components. [z,y,x]
    • equivalent

      public boolean equivalent(@Nonnull Vector3 v)
      Returns whether this vector is equivalent to given vector.
      Parameters:
      v - the quaternion to compare.
      Returns:
      true if this vector is equivalent to other.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      @Nonnull public Vector3 copy()