rotateX function

List<double> rotateX(
  1. List<double> out,
  2. List<double> a,
  3. List<double> b,
  4. double rad
)

Rotate a 3D vector around the x-axis @param {vec3} out The receiving vec3 @param {ReadonlyVec3} a The vec3 point to rotate @param {ReadonlyVec3} b The origin of the rotation @param {Number} rad The angle of rotation in radians @returns {vec3} out

Implementation

List<double> rotateX(List<double> out, List<double> a, List<double> b, double rad) {
  final p = [], r = [];
  //Translate point to the origin
  p[0] = a[0] - b[0];
  p[1] = a[1] - b[1];
  p[2] = a[2] - b[2];

  //perform rotation
  r[0] = p[0];
  r[1] = p[1] * math.cos(rad) - p[2] * math.sin(rad);
  r[2] = p[1] * math.sin(rad) + p[2] * math.cos(rad);

  //translate to correct position
  out[0] = r[0] + b[0];
  out[1] = r[1] + b[1];
  out[2] = r[2] + b[2];

  return out;
}