setFromVectors method

Quaternion setFromVectors(
  1. Vec3 u,
  2. Vec3 v
)

Set the quaternion value given two vectors. The resulting rotation will be the needed rotation to rotate u to v.

Implementation

Quaternion setFromVectors(Vec3 u, Vec3 v){
  if (u.isAntiparallelTo(v)) {
    final t1 = _sfvT1;
    final t2 = _sfvT2;

    u.tangents(t1, t2);
    setFromAxisAngle(t1, math.pi);
  } else {
    final a = u.cross(v);
    x = a.x;
    y = a.y;
    z = a.z;
    w = math.sqrt(math.pow(u.length(),2) * math.pow(v.length(),2)) + u.dot(v);
    normalize();
  }
  return this;
}