Maven module :un.api : api-math :
Class : un.impl.math.Vectors
Extends/Implements : -
Subclasses : -

author  Johann Sorel
author  Bertrand COTE


Variables : -
Functions : length, length, lengthSquare, lengthSquare, shortestAngle, shortestAngle, clampEuler, cos, cos, sin, sin, reflect, add, add, subtract, subtract, multiply, multiply, divide, divide, scale, scale, cross, cross, dot, dot, normalize, normalize, negate, negate, lerp, lerp, add, add, subtract, subtract, multiply, multiply, divide, divide, scale, scale, cross, cross, normalize, normalize, negate, negate, lerp, lerp, add, add, addRegular, addRegular, subtract, subtract, subtractRegular, subtractRegular, scaleRegular, scaleRegular, multiplyRegular, multiplyRegular, divideRegular, divideRegular, cartesianToPolar, cartesianToPolar, polarToCartesian, polarToCartesian, cartesianToCylindrical, cartesianToCylindrical, cylindricalToCartesian, cylindricalToCartesian, cartesianToSpherical, cartesianToSpherical, sphericalToCartesian, sphericalToCartesian




Computes the vector's length.
param  vector
return
public double length (double[] vector)


Computes the vector's length.
param  vector
return
public float length (float[] vector)


Computes the vector's square length.
param  vector
return
public double lengthSquare (double[] vector)


Computes the vector's square length.
param  vector
return
public float lengthSquare (float[] vector)


Computes the shortest angle between given vectors.
formula : acos(dot(vector,other)/(length(vector)*length(other)))
param  vector
param  other
return  shortest angle in radian
public double shortestAngle (double[] vector, double[] other)


Computes the shortest angle between given vectors.
formula : acos(dot(vector,other)/(length(vector)*length(other)))
param  vector
param  other
return  shortest angle in radian
public float shortestAngle (float[] vector, float[] other)


Ensure the given Euler angles are in the proper ranges.
public void clampEuler (double[] euler)


Cosine of the angle between the two vectors.
formula : dot(vector,other)
param  vector
param  other
return
public double cos (double[] vector, double[] other)


Cosine of the angle between the two vectors.
formula : dot(vector,other)
param  vector
param  other
return
public float cos (float[] vector, float[] other)


Sinus of the angle between the two vectors.
The returned value is signed for 2D vectors, and unsigned for 3D vectors.
param  vector
param  other
return
public double sin (double[] vector, double[] other)


Sinus of the angle between the two vectors.
The returned value is signed for 2D vectors, and unsigned for 3D vectors.
param  vector
param  other
return
public float sin (float[] vector, float[] other)


Calculate reflection vector.
https://en.wikipedia.org/wiki/Reflection_(physics)
Formula :
r = v - 2(v • n)n
param  vector
param  normal
return
public double[] reflect (double[] vector, double[] normal)


Add vector and other.
Vectors must have the same size.
param  vector
param  other
return
public double[] add (double[] vector, double[] other)


Add vector and other.
Vectors must have the same size.
param  vector
param  other
return
public float[] add (float[] vector, float[] other)


Subtract vector and other.
Vectors must have the same size.
param  vector
param  other
return
public double[] subtract (double[] vector, double[] other)


Subtract vector and other.
Vectors must have the same size.
param  vector
param  other
return
public float[] subtract (float[] vector, float[] other)


Multiply vector and other.
Vectors must have the same size.
param  vector
param  other
return
public double[] multiply (double[] vector, double[] other)


Multiply vector and other.
Vectors must have the same size.
param  vector
param  other
return
public float[] multiply (float[] vector, float[] other)


Divide vector and other.
Vectors must have the same size.
param  vector numerators vector.
param  other denominators vector.
return
public double[] divide (double[] vector, double[] other)


Divide vector and other.
Vectors must have the same size.
param  vector numerators vector.
param  other denominators vector.
return
public float[] divide (float[] vector, float[] other)


Scale vector by the given scale.
param  vector the vector to scale.
param  scale the scale coefficient.
return  the scaled vector.
public double[] scale (double[] vector, double scale)


Scale vector by the given scale.
param  vector the vector to scale.
param  scale the scale coefficient.
return  the scaled vector.
public float[] scale (float[] vector, float scale)


Cross product of v1 and v2.
Vectors must have size 3.
param  vector
param  other
return  the cross product of vector by other.
public double[] cross (double[] vector, double[] other)


Cross product of v1 and v2.
Vectors must have size 3.
param  vector
param  other
return  the cross product of vector by other.
public float[] cross (float[] vector, float[] other)


Dot product of vector and other.
Vectors must have the same size.
param  vector
param  other
return
public double dot (double[] vector, double[] other)


Dot product of vector and other.
Vectors must have the same size.
param  vector
param  other
return
public float dot (float[] vector, float[] other)


Normalizes vector.
Vectors must have the same size.
param  vector the vector to normalize.
return  the normalized vector.
public double[] normalize (double[] vector)


Normalizes vector.
Vectors must have the same size.
param  vector the vector to normalize.
return  the normalized vector.
public float[] normalize (float[] vector)


Negates the vector, equivalent to multiply all values by -1.
param  vector the vector to negate.
return  the negated vector.
public double[] negate (double[] vector)


Negates the vector, equivalent to multiply all values by -1.
param  vector the vector to negate.
return  the negated vector.
public float[] negate (float[] vector)


Interpolates between given vectors.
param  start start vector (return value for ratio == 0.)
param  end end vector (return value for ratio == 1.)
param  ratio : 0 is close to start vector, 1 is on end vector
return  the interpolated vector.
public double[] lerp (double[] start, double[] end, double ratio)


Interpolates between given vectors.
param  start start vector (return value for ratio == 0.)
param  end end vector (return value for ratio == 1.)
param  ratio : 0 is close to start vector, 1 is on end vector
return  the interpolated vector.
public float[] lerp (float[] start, float[] end, float ratio)


Add vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public double[] add (double[] vector, double[] other, double[] buffer)


Add vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public float[] add (float[] vector, float[] other, float[] buffer)


Subtract vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public double[] subtract (double[] vector, double[] other, double[] buffer)


Subtract vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public float[] subtract (float[] vector, float[] other, float[] buffer)


Multiply vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public double[] multiply (double[] vector, double[] other, double[] buffer)


Multiply vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector
param  other
param  buffer must have same size as vector or be null.
return
public float[] multiply (float[] vector, float[] other, float[] buffer)


Divide vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector numerators vector.
param  other denominators vector.
param  buffer must have same size as vector or be null.
return
public double[] divide (double[] vector, double[] other, double[] buffer)


Divide vector and other, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size.
param  vector numerators vector.
param  other denominators vector.
param  buffer must have same size as vector or be null.
return
public float[] divide (float[] vector, float[] other, float[] buffer)


Scale vector by the given scale, result is stored in buffer.
If buffer is null, a new vector is created.
param  vector the vector to scale.
param  scale the scale coefficient.
param  buffer must have same size as vector or be null.
return  the scaled vector.
public double[] scale (double[] vector, double scale, double[] buffer)


Scale vector by the given scale, result is stored in buffer.
If buffer is null, a new vector is created.
param  vector the vector to scale.
param  scale the scale coefficient.
param  buffer must have same size as vector or be null.
return  the scaled vector.
public float[] scale (float[] vector, float scale, float[] buffer)


Cross product of v1 and v2. result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have size 3.
param  vector
param  other
param  buffer must have same size as vector and other or be null.
return  the cross product of vector by other.
public double[] cross (double[] vector, double[] other, double[] buffer)


Cross product of v1 and v2. result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have size 3.
param  vector
param  other
param  buffer must have same size as vector and other or be null.
return  the cross product of vector by other.
public float[] cross (float[] vector, float[] other, float[] buffer)


Normalizes vector, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size
param  vector the vector to normalize.
param  buffer must have same size as vector or be null.
return  the normalized vector.
public double[] normalize (double[] vector, double[] buffer)


Normalizes vector, result is stored in buffer.
If buffer is null, a new vector is created.
Vectors must have the same size
param  vector the vector to normalize.
param  buffer must have same size as vector or be null.
return  the normalized vector.
public float[] normalize (float[] vector, float[] buffer)


Negates the vector, equivalent to multiply all values by -1.
param  vector the vector to negate.
param  buffer must have same size as vector or be null.
return  the negated vector.
public double[] negate (double[] vector, double[] buffer)


Negates the vector, equivalent to multiply all values by -1.
param  vector the vector to negate.
param  buffer must have same size as vector or be null.
return  the negated vector.
public float[] negate (float[] vector, float[] buffer)


Interpolates between given vectors.
param  start start vector (return value for ratio == 0.)
param  end end vector (return value for ratio == 1.)
param  ratio : 0 is close to start vector, 1 is on end vector
param  buffer must have same size as start and end or be null.
return  the interpolated vector.
public double[] lerp (double[] start, double[] end, double ratio, double[] buffer)


Interpolates between given vectors.
param  start start vector (return value for ratio == 0.)
param  end end vector (return value for ratio == 1.)
param  ratio : 0 is close to start vector, 1 is on end vector
param  buffer must have same size as start and end or be null.
return  the interpolated vector.
public float[] lerp (float[] start, float[] end, float ratio, float[] buffer)


Add source1 and source2, result is stored in buffer.
param  source1
param  source2
param  buffer
param  source1Offset
param  source2Offset
param  bufferOffset
param  tupleSize
param  nbTuple
return  buffer
public double[] add (double[] source1, double[] source2, double[] buffer, int source1Offset, int source2Offset, int bufferOffset, int tupleSize, int nbTuple)


Add source1 and source2, result is stored in buffer.
param  source1
param  source2
param  buffer
param  source1Offset
param  source2Offset
param  bufferOffset
param  tupleSize
param  nbTuple
return  buffer
public float[] add (float[] source1, float[] source2, float[] buffer, int source1Offset, int source2Offset, int bufferOffset, int tupleSize, int nbTuple)


Add 'addition' to all source1 elements, result is stored in buffer.
@param source1
@param buffer
@param source1Offset
@param bufferOffset
@param addition
@param nbTuple
@return buffer
public double[] addRegular (double[] source1, double[] buffer, int source1Offset, int bufferOffset, double[] addition, int nbTuple)


Add 'addition' to all source1 elements, result is stored in buffer.
@param source1
@param buffer
@param source1Offset
@param bufferOffset
@param addition
@param nbTuple
@return buffer
public float[] addRegular (float[] source1, float[] buffer, int source1Offset, int bufferOffset, float[] addition, int nbTuple)


Substract source1 and source2, result is stored in buffer.
param  source1
param  source2
param  buffer
param  source1Offset
param  source2Offset
param  bufferOffset
param  tupleSize
param  nbTuple
return  buffer
public double[] subtract (double[] source1, double[] source2, double[] buffer, int source1Offset, int source2Offset, int bufferOffset, int tupleSize, int nbTuple)


Substract source1 and source2, result is stored in buffer.
param  source1
param  source2
param  buffer
param  source1Offset
param  source2Offset
param  bufferOffset
param  tupleSize
param  nbTuple
return  buffer
public float[] subtract (float[] source1, float[] source2, float[] buffer, int source1Offset, int source2Offset, int bufferOffset, int tupleSize, int nbTuple)


Substract 'substraction' to all source1 elements, result is stored in buffer.
@param source1
@param buffer
@param source1Offset
@param bufferOffset
@param substraction
@param nbTuple
@return buffer
public double[] subtractRegular (double[] source1, double[] buffer, int source1Offset, int bufferOffset, double[] substraction, int nbTuple)


Substract 'substraction' to all source1 elements, result is stored in buffer.
@param source1
@param buffer
@param source1Offset
@param bufferOffset
@param substraction
@param nbTuple
@return buffer
public float[] subtractRegular (float[] source1, float[] buffer, int source1Offset, int bufferOffset, float[] substraction, int nbTuple)


Scale source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  tupleSize
param  nbTuple
return  buffer
public double[] scaleRegular (double[] source1, double[] buffer, int source1Offset, int bufferOffset, double scale, int tupleSize, int nbTuple)


Scale source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  tupleSize
param  nbTuple
return  buffer
public float[] scaleRegular (float[] source1, float[] buffer, int source1Offset, int bufferOffset, float scale, int tupleSize, int nbTuple)


Scale source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  nbTuple
return  buffer
public double[] multiplyRegular (double[] source1, double[] buffer, int source1Offset, int bufferOffset, double[] scale, int nbTuple)


Scale source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  nbTuple
return  buffer
public float[] multiplyRegular (float[] source1, float[] buffer, int source1Offset, int bufferOffset, float[] scale, int nbTuple)


Divide source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  nbTuple
return  buffer
public double[] divideRegular (double[] source1, double[] buffer, int source1Offset, int bufferOffset, double[] scale, int nbTuple)


Divide source1, result is stored in buffer.
param  source1
param  buffer
param  source1Offset
param  bufferOffset
param  scale
param  nbTuple
return  buffer
public float[] divideRegular (float[] source1, float[] buffer, int source1Offset, int bufferOffset, float[] scale, int nbTuple)


From cartesian to polar coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_polar_coordinates_from_Cartesian_coordinates


@param cartesian { x, y }
@return { r, theta }
public double[] cartesianToPolar (double[] cartesian)


From cartesian to polar coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_polar_coordinates_from_Cartesian_coordinates


@param cartesian { x, y }
@return { r, theta }
public float[] cartesianToPolar (float[] cartesian)


From polar to cartesian coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_Cartesian_coordinates_from_polar_coordinates


@param polar { r, theta }
@return { x, y }
public double[] polarToCartesian (double[] polar)


From polar to cartesian coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_Cartesian_coordinates_from_polar_coordinates


@param polar { r, theta }
@return { x, y }
public float[] polarToCartesian (float[] polar)


From cartesian to cylindrical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_Coordinates_2


@param cartesian { x, y, z }
@return { r, theta, z }
public double[] cartesianToCylindrical (double[] cartesian)


From cartesian to cylindrical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_Coordinates_2


@param cartesian { x, y, z }
@return { r, theta, z }
public float[] cartesianToCylindrical (float[] cartesian)


From cartesian to cylindrical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_Coordinates_2


@param cylindrical { r, theta, z }
@return { x, y, z }
public double[] cylindricalToCartesian (double[] cylindrical)


From cartesian to cylindrical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_Coordinates_2


@param cylindrical { r, theta, z }
@return { x, y, z }
public float[] cylindricalToCartesian (float[] cylindrical)


From cartesian to spherical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_coordinates


@param cartesian { x, y, z }
@return { rho, theta, phi }
public double[] cartesianToSpherical (double[] cartesian)


From cartesian to spherical coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_coordinates


@param cartesian { x, y, z }
@return { rho, theta, phi }
public float[] cartesianToSpherical (float[] cartesian)


From spherical to cartesian coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_spherical_coordinates


@param spherical { rho, theta, phi }
@return { x, y, z }
public double[] sphericalToCartesian (double[] spherical)


From spherical to cartesian coordinate system transformation.
http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_spherical_coordinates


@param spherical { rho, theta, phi }
@return { x, y, z }
public float[] sphericalToCartesian (float[] spherical)