MATLAB: Ho do I calculate the angle between two 3d triangles

cudageometrygpumathematicsMATLABtrigonometry

Is it possible to compute angle between two 3d triangles always sharing two vertices?
Let's assume triangle1 consists of three points
P1=(x1,y1,z1), P2=(x2,y2,z2), and P3=(x3,y3,z3).
Triangle2 consists of the following three points
P1=(x1,y1,z1), P2=(x2,y2,z2), and P3=(x4,y4,z4).

Best Answer

P1=randn(3,1)
P2=randn(3,1)
P3=randn(3,1)
P4=randn(3,1)
E=P1-P2 % edge
Q = null(E')
v1 = Q'*(P3-P1)
v2 = Q'*(P4-P1)
theta1 = atan2(v1(2),v1(1))
theta2 = atan2(v2(2),v2(1))
theta = mod(theta1-theta2,2*pi) % radian
% Bruno
Note that there is always an ambiguity of the sign of the angle when working on 3D,