// https://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another public static Rot3f HalfWayVec(V3f from, V3f into) { if (from.Dot(into).ApproximateEquals(-1)) { return(new Rot3f(0, from.AxisAlignedNormal())); } else { V3f half = Vec.Normalized(from + into); QuaternionF q = new QuaternionF(Vec.Dot(from, half), Vec.Cross(from, half)); return(new Rot3f(q.Normalized)); } }
public static Rot3f HalfWayQuat(V3f from, V3f into) { var d = Vec.Dot(from, into); if (d.ApproximateEquals(-1)) { return(new Rot3f(0, from.AxisAlignedNormal())); } else { QuaternionF q = new QuaternionF(d + 1, Vec.Cross(from, into)); return(new Rot3f(q.Normalized)); } }
public static Rot3f Original(V3f from, V3f into) { var angle = from.AngleBetween(into); if (angle < 1e-6f) { return(Rot3f.Identity); } else if (Constant.PiF - angle < 1e-6f) { return(new Rot3f(0, from.AxisAlignedNormal())); } else { V3f axis = Vec.Cross(from, into).Normalized; return(Rot3f.Rotation(axis, angle)); } }