Quaternion.fromVectors constructor

Quaternion.fromVectors(
  1. List<num> source,
  2. List<num> target
)

Constructs a quaternion from the rotation between two vectors source and target.

Implementation

factory Quaternion.fromVectors(List<num> source, List<num> target) {
  final w =
      source[0] * target[0] + source[1] * target[1] + source[2] * target[2];
  final x = source[1] * target[2] - source[2] * target[1];
  final y = source[2] * target[0] - source[0] * target[2];
  final z = source[0] * target[1] - source[1] * target[0];
  return Quaternion(w + (w * w + x * x + y * y + z * z).sqrt(), x, y, z)
      .normalize();
}