Q:

How to calculate the quaternion that represents a triangle's 3D rotation?

Or to look at it another way, let's say we have 2 same size triangles located and orientated at different parts of 3D space. How do you calculate the quaternion that describes the rotation such that applying the quaternion to triangle A would have it sit at triangle B? It is difficult to see how finding the normal of A and B and calculating the quaternion from this would work because the normal vector does not contain information about rotation (or rather, it assumes the standard base frame for the normals of both triangles thus throwing away valuable information). It seems you would need to find the vectors from each triangles (a, b, c) to the others (a, b, c) and somehow construct a quaternion out of this. Way beyond me, and could any mathematicians please dumb it down. 

A:

First orient the normal vectors then the plane.
Source=(s1,s2,s3)
Target=(t1,t2,t3)
NormSource = (s1 - s2)cross(s1 - s3)
NormTarget = (t1 - t2)cross(t1 - t3)
Quat1 = getRotationTo (NormSource,NormTarget)
Quat2 = getRotationTo ( Quat1 * (s1 - s2),(t1 - t2) );
QuatFinal = Quat2 * Quat1

