# Class: ExtMath

### LuxModule: luxinialuacore

The Extended Math class contains some generic math operations. Vectors and matrices are passed as indexed tables from 1-3 or 1-16. Matrices are stored column-major. Compared to the Luxinia CoreApi functions, the operations here are written and processed entirely in Lua

## Methods:

### Method overview:

- anglediff
- interpolate
- nearestpowerof2
- nextpowerof2
- quatslerp
- spline
- v3add
- v3axisrotate
- v3cross
- v3dist
- v3div
- v3dot
- v3interpolate
- v3len
- v3mul
- v3normalize
- v3polar
- v3scale
- v3scaledadd
- v3spline
- v3sqdist
- v3sqlen
- v3sub
- v4add
- v4div
- v4interpolate
- v4mul
- v4scale
- v4scaledadd
- v4spline
- v4sub

anglediff (radians1, radians2)
  returns: (angle)
  calculates the shortest angledifference between two angles (which is a bit tricky i.e. -Math.PI - Math.PI == 0)
interpolate (float fraction,float from, float to)
  returns: (float)
  returns interpolated value between from and to
nearestpowerof2 (number)
  returns: (number)
  calculates the nearest positive power of 2 number
nextpowerof2 (number)
  returns: (number)
  calculates the next positive power of 2 number
quatslerp (number fracc, table q1, q2)
  returns: (tabel qout)
  returns quaternion spherical interoplation
spline (float fraction,float prevfrom, float from, float to, float nextto)
  returns: (float)
  returns catmull-rom spline interpolated value between from and to
v3add (table a,b)
  returns: (table sum)
  returns addition a + b
v3axisrotate (table axis,number angle, table vec)
  returns: (table point)
  rotates vector vec around angle of the given axis
v3cross (table a, b)
  returns: (table vector)
  returns cross product of 3d vector a and b
v3dist (table v1,v2)
  returns: (float sqdist)
  return distance |(v1-v2)| of vectors
v3div (table a,b)
  returns: (table out)
  returns componentwise multiplication a / b
v3dot (table v1, v2)
  returns: (float dot)
  returns dotproduct for 2 3vectors
v3interpolate (float fraction,table from, table to)
  returns: (table)
  returns interpolated vector between from and to
v3len (table vec)
  returns: (float len)
  euklid length of vecotr (a²+b²+c²)^0.5
v3mul (table a,b)
  returns: (table out)
  returns componentwise multiplication a * b
v3normalize (table vec)
  returns: (table normalized,float origlength)
  returns normalized vector 3d vector and the original length of the vector
v3polar (float len,planeangle,heightangle)
  returns: (floar x,y,z)
  converts polar coords to regular x,y,z
v3scale (table a,float f)
  returns: (table out)
  returns component wise a * f
v3scaledadd (table a,table b,float f)
  returns: (table out)
  returns a + (b * f)
v3spline (float fraction, table prevfrom, table from, table to, table nextto)
  returns: (table)
  returns catmull-rom spline interpolated vector between from and to
v3sqdist (table v1,v2)
  returns: (float sqdist)
  return square distance |(v1-v2)|² of vectors
v3sqlen (table vec)
  returns: (float len)
  square distance. This function is a little bit faster than the len function which returns the squareroot of this function. If you only want to compare distances (i.e. is this point inside my distance), you can square the distance you would like to compare with. This is worth the effort since it does not make much difference in code and work.
v3sub (table a,b)
  returns: (table difference)
  returns subraction a - b
v4add (table a,b)
  returns: (table sum)
  returns addition a + b
v4div (table a,b)
  returns: (table out)
  returns componentwise multiplication a / b
v4interpolate (float fraction,table from, table to)
  returns: (table)
  returns interpolated vector between from and to
v4mul (table a,b)
  returns: (table out)
  returns componentwise multiplication a * b
v4scale (table a,float f)
  returns: (table out)
  returns component wise a * f
v4scaledadd (table a,table b, float f)
  returns: (table out)
  returns a + (b * f)
v4spline (float fraction, table prevfrom, table from, table to, table nextto)
  returns: (table)
  returns catmull-rom spline interpolated vector between from and to
v4sub (table a,b)
  returns: (table difference)
  returns subraction a - b