Package com.smartfoxserver.entities.data
Class SFSVector3
java.lang.Object
com.smartfoxserver.entities.data.SFSVector3
- All Implemented Interfaces:
Serializable
A class representing a Vector in 23 space
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Returns a new vector with all components in absolute values.ceil()Returns a new vector with all components rounded up to the nearest integer.cross(SFSVector3 vec) Returns the cross product of this vector and the specified vector.floatReturns the squared distance between this vector and the specified vector.floatdistanceTo(SFSVector3 vec) Returns the Euclidean distance between this vector and the specified vector.divide(SFSVector3 vec) Returns a new vector that is the component-wise division of this vector by the specified vector.floatdot(SFSVector3 vec) Returns the dot product of this vector and the specified vector.static SFSVector3empty()booleanfloor()Returns a new vector with all components rounded down to the nearest integer.booleanReturns true if the vector is normalized, i.e., its length is approximately equal to 1.floatlength()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.max(SFSVector3 vec) Returns a new vector with the component-wise maximum of this vector and the specified vector.min(SFSVector3 vec) Returns a new vector with the component-wise minimum of this vector and the specified vector.mult(SFSVector3 vec) 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.round()Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero.sub(SFSVector3 vec) Returns a new vector that is the result of subtracting the specified vector from this vector.sum(SFSVector3 vec) Returns a new vector that is the sum of this vector and the specified vector.toString()
-
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
-
-
Method Details
-
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
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
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
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
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
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
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
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
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
Returns a new vector with all components in absolute values.- Returns:
- a new vector with absolute values
-
min
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
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
Returns a new vector with all components rounded down to the nearest integer.- Returns:
- a new vector with floored components
-
ceil
Returns a new vector with all components rounded up to the nearest integer.- Returns:
- a new vector with ceiling components
-
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
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 towardsweight- the interpolation weight (0.0 = this vector, 1.0 = target vector)- Returns:
- a new interpolated vector
- Throws:
IllegalArgumentException- if vec is null
-
cross
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
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
-
toString
-