rotPointFromFormula static method

Vector3 rotPointFromFormula(
  1. double a,
  2. double b,
  3. double c,
  4. double u,
  5. double v,
  6. double w,
  7. double x,
  8. double y,
  9. double z,
  10. double theta,
)

Compute the rotated point from the formula given in the paper, as opposed to multiplying this matrix by the given point. Theoretically this should give the same answer as timesXYZ. For repeated calculations this will be slower than using timesXYZ because, in effect, it repeats the calculations done in the constructor.

This method is static partly to emphasize that it does not mutate an instance of RotationMatrix, even though it uses the same parameter names as the the constructor.

a x-coordinate of a point on the line of rotation. b y-coordinate of a point on the line of rotation. c z-coordinate of a point on the line of rotation. u x-coordinate of the line's direction vector. This direction vector will be normalized. v y-coordinate of the line's direction vector. w z-coordinate of the line's direction vector. x The point's x-coordinate. y The point's y-coordinate. z The point's z-coordinate. theta The angle of rotation, in radians.

Returns the product, in a Vector3, representing the rotated point.

Implementation

static Vector3 rotPointFromFormula(double a, double b, double c, double u,
    double v, double w, double x, double y, double z, double theta) {
  // We normalize the direction vector.

  final l = _longEnough(u, v, w);
  if (l < 0) {
    throw (Exception('RotationMatrix direction vector too short'));
  }
  // Normalize the direction vector.
  u = u / l; // Note that is not "this.u".
  v = v / l;
  w = w / l;
  // Set some intermediate values.
  final u2 = u * u;
  final v2 = v * v;
  final w2 = w * w;
  final cosT = math.cos(theta);
  final oneMinusCosT = 1 - cosT;
  final sinT = math.sin(theta);

  // Use the formula in the paper.
  final p = Vector3(0.0, 0.0, 0.0);
  p[0] = (a * (v2 + w2) - u * (b * v + c * w - u * x - v * y - w * z)) *
          oneMinusCosT +
      x * cosT +
      (-c * v + b * w - w * y + v * z) * sinT;

  p[1] = (b * (u2 + w2) - v * (a * u + c * w - u * x - v * y - w * z)) *
          oneMinusCosT +
      y * cosT +
      (c * u - a * w + w * x - u * z) * sinT;

  p[2] = (c * (u2 + v2) - w * (a * u + b * v - u * x - v * y - w * z)) *
          oneMinusCosT +
      z * cosT +
      (-b * u + a * v - v * x + u * y) * sinT;

  return p;
}