Vector3RotateByAxisAngle function

Vector3 Vector3RotateByAxisAngle(
  1. Vector3 v,
  2. Vector3 axis,
  3. double angle
)

Rotate v around axis by angle (radians) — Rodrigues' formula.

Implementation

Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, double angle) {
  final a = axis.normalized();
  final c = math.cos(angle), s = math.sin(angle);
  return v.scaled(c) + a.cross(v).scaled(s) + a.scaled(a.dot(v) * (1 - c));
}