QuaternionFromVector3ToVector3 function
Rotation quaternion from one vector direction to another.
Implementation
Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to) {
final f = from.normalized(), t = to.normalized();
final dot = f.dot(t);
if ((dot + 1.0).abs() < 1e-6) {
final perp = Vector3Perpendicular(f);
return Quaternion(perp.x, perp.y, perp.z, 0.0)..normalize();
}
final cross = f.cross(t);
return Quaternion(cross.x, cross.y, cross.z, 1.0 + dot)..normalize();
}