Class SFSVector3

java.lang.Object
com.smartfoxserver.entities.data.SFSVector3
All Implemented Interfaces:
Serializable

public class SFSVector3 extends Object implements Serializable
A class representing a Vector in 23 space
See Also:
  • Field Summary

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

    Constructors
    Constructor
    Description
    SFSVector3(float x, float y, float z)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Returns a new vector with all components in absolute values.
    Returns a new vector with all components rounded up to the nearest integer.
    Returns the cross product of this vector and the specified vector.
    float
    Returns the squared distance between this vector and the specified vector.
    float
    Returns the Euclidean distance between this vector and the specified vector.
    Returns a new vector that is the component-wise division of this vector by the specified vector.
    float
    Returns the dot product of this vector and the specified vector.
    static SFSVector3
     
    boolean
    equals(Object other)
     
    Returns a new vector with all components rounded down to the nearest integer.
    boolean
    Returns true if the vector is normalized, i.e., its length is approximately equal to 1.
    float
    Returns the length (magnitude) of this vector.
    lerp(SFSVector3 vec, float weight)
    Returns the result of the linear interpolation between this vector and the specified vector by the specified weight.
    Returns a new vector with the component-wise maximum of this vector and the specified vector.
    Returns a new vector with the component-wise minimum of this vector and the specified vector.
    Returns a new vector that is the component-wise multiplication of this vector and the specified vector.
    Returns a new vector that is the normalized (unit length) version of this vector.
    rotate(SFSVector3 axis, float angle)
    Returns a new vector that is the result of rotating this vector around the specified axis by the specified angle.
    Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
    Returns a new vector that is the result of subtracting the specified vector from this vector.
    Returns a new vector that is the sum of this vector and the specified vector.
     

    Methods inherited from class java.lang.Object

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

    • x

      public float x
    • y

      public float y
    • z

      public float z
  • Constructor Details

    • SFSVector3

      public SFSVector3(float x, float y, float z)
    • SFSVector3

      public SFSVector3(SFSVector3 vec3)
  • Method Details

    • empty

      public static SFSVector3 empty()
    • length

      public float length()
      Returns the length (magnitude) of this vector.
      Returns:
      the length of the vector
    • isNormalized

      public boolean isNormalized()
      Returns true if the vector is normalized, i.e., its length is approximately equal to 1.
      Returns:
      true if the vector is normalized, false otherwise
    • sum

      public SFSVector3 sum(SFSVector3 vec)
      Returns a new vector that is the sum of this vector and the specified vector.
      Parameters:
      vec - the vector to add
      Returns:
      a new vector representing the sum
      Throws:
      IllegalArgumentException - if vec is null
    • sub

      public SFSVector3 sub(SFSVector3 vec)
      Returns a new vector that is the result of subtracting the specified vector from this vector.
      Parameters:
      vec - the vector to subtract
      Returns:
      a new vector representing the difference
      Throws:
      IllegalArgumentException - if vec is null
    • mult

      public SFSVector3 mult(SFSVector3 vec)
      Returns a new vector that is the component-wise multiplication of this vector and the specified vector.
      Parameters:
      vec - the vector to multiply with
      Returns:
      a new vector representing the component-wise product
      Throws:
      IllegalArgumentException - if vec is null
    • divide

      public SFSVector3 divide(SFSVector3 vec)
      Returns a new vector that is the component-wise division of this vector by the specified vector. If any component of the divisor is zero, the result will be Infinity or NaN.
      Parameters:
      vec - the vector to divide by
      Returns:
      a new vector representing the component-wise quotient
      Throws:
      IllegalArgumentException - if vec is null
    • normalize

      public SFSVector3 normalize()
      Returns a new vector that is the normalized (unit length) version of this vector. If this vector has zero length, returns a zero vector.
      Returns:
      a new normalized vector
    • dot

      public float dot(SFSVector3 vec)
      Returns the dot product of this vector and the specified vector. The dot product will be 0 for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees. When using unit (normalized) vectors, the result will always be between -1.0 (180 degree angle) when the vectors are facing opposite directions, and 1.0 (0 degree angle) when the vectors are aligned.
      Parameters:
      vec - the vector to compute the dot product with
      Returns:
      the dot product
      Throws:
      IllegalArgumentException - if vec is null
    • distanceTo

      public float distanceTo(SFSVector3 vec)
      Returns the Euclidean distance between this vector and the specified vector.
      Parameters:
      vec - the vector to measure distance to
      Returns:
      the distance between the two vectors
      Throws:
      IllegalArgumentException - if vec is null
    • distanceSquaredTo

      public float distanceSquaredTo(SFSVector3 vec)
      Returns the squared distance between this vector and the specified vector. This is more efficient than distanceTo() when comparing distances.
      Parameters:
      vec - the vector to measure squared distance to
      Returns:
      the squared distance between the two vectors
      Throws:
      IllegalArgumentException - if vec is null
    • abs

      public SFSVector3 abs()
      Returns a new vector with all components in absolute values.
      Returns:
      a new vector with absolute values
    • min

      public SFSVector3 min(SFSVector3 vec)
      Returns a new vector with the component-wise minimum of this vector and the specified vector.
      Parameters:
      vec - the vector to compare with
      Returns:
      a new vector with the minimum components
      Throws:
      IllegalArgumentException - if vec is null
    • max

      public SFSVector3 max(SFSVector3 vec)
      Returns a new vector with the component-wise maximum of this vector and the specified vector.
      Parameters:
      vec - the vector to compare with
      Returns:
      a new vector with the maximum components
      Throws:
      IllegalArgumentException - if vec is null
    • floor

      public SFSVector3 floor()
      Returns a new vector with all components rounded down to the nearest integer.
      Returns:
      a new vector with floored components
    • ceil

      public SFSVector3 ceil()
      Returns a new vector with all components rounded up to the nearest integer.
      Returns:
      a new vector with ceiling components
    • round

      public SFSVector3 round()
      Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.
      Returns:
      a new vector with rounded components
    • lerp

      public SFSVector3 lerp(SFSVector3 vec, float weight)
      Returns the result of the linear interpolation between this vector and the specified vector by the specified weight. The weight range is 0.0 to 1.0, representing the amount of interpolation. Values outside this range will extrapolate.
      Parameters:
      vec - the target vector to interpolate towards
      weight - the interpolation weight (0.0 = this vector, 1.0 = target vector)
      Returns:
      a new interpolated vector
      Throws:
      IllegalArgumentException - if vec is null
    • cross

      public SFSVector3 cross(SFSVector3 vec)
      Returns the cross product of this vector and the specified vector. The cross product is a vector perpendicular to both vectors.
      Parameters:
      vec - the vector to compute the cross product with
      Returns:
      a new vector representing the cross product
      Throws:
      IllegalArgumentException - if vec is null
    • rotate

      public SFSVector3 rotate(SFSVector3 axis, float angle)
      Returns a new vector that is the result of rotating this vector around the specified axis by the specified angle. This uses Rodrigues' rotation formula.
      Parameters:
      axis - the axis to rotate around (must be a normalized vector)
      angle - the angle to rotate by, in radians
      Returns:
      a new rotated vector
      Throws:
      IllegalArgumentException - if axis is null or not normalized
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object