I'm working with 3D mesh data, where I have lots of 3D triangles which I need to rotate to eliminate the Z value, converting it to a 2D triangle.
With this 2D triangle I'm doing some vector calculations.
After I'm done with my work I need to rotate it back to the original angle such that the old points return back to their original positions, to fit back into the 3D mesh.
Edit: This is the code I'm using.
I can't figure out how to reverse the rotation.
Inputs
var p1:Object, p2:Object, p3:Object;
Find face normal
var norm:Object = calcNormal(p1,p2,p3);
Find rotation angles based on normal
sinteta = -norm.y / Math.sqrt(norm.x * norm.x + norm.y * norm.y);
costeta = norm.x / Math.sqrt(norm.x * norm.x + norm.y * norm.y);
sinfi = -Math.sqrt(norm.x * norm.x + norm.y * norm.y);
cosfi = norm.z;
Rotate around Z and then Y to align to the z plane.
lx = costeta * cosfi;
ly = -sinteta * cosfi;
lz = sinfi;
mx = sinteta;
my = costeta;
mz = 0;
nx = -sinfi * costeta;
ny = sinfi * sinteta;
nz = cosfi;
var np1:Object = {};
np1.x=p1.x*lx + p1.y*ly + p1.z*lz;
np1.y=p1.x*mx + p1.y*my + p1.z*mz;
np1.z=p1.x*nx + p1.y*ny + p1.z*nz;
var np2:Object = {};
np2.x=p2.x*lx + p2.y*ly + p2.z*lz;
np2.y=p2.x*mx + p2.y*my + p2.z*mz;
np2.z=p2.x*nx + p2.y*ny + p2.z*nz;
var np3:Object = {};
np3.x=p3.x*lx + p3.y*ly + p3.z*lz;
np3.y=p3.x*mx + p3.y*my + p3.z*mz;
np3.z=p3.x*nx + p3.y*ny + p3.z*nz;