(* Rotation of general triangle into xy plane with one point (O atom) at 0rigine by translation, one leg on x-axis O - C atoms; example: COH in Vitamine A    ES 15.3.2013 *)
Clear[T1,U,T,P,p];
P=2;
p={{0.8910058089999993`,-1.2609385707599998`,2.215514762399999`},
{-1.3556894324000002`,-1.02001740302`,-0.6789785517999993`}};

c1=20; c2=21; c3=51;
v2={0,0,0};
u2={0.2557`,0.255`,0.255`,0.2557`,0.255`,0.2557`,0.2547`,0.2547`,0.2557`,0.2547`,0.2557`,0.2557`,0.2547`,0.2557`,0.2557`,0.2557`,0.2557`,0.2547`,0.2557`,0.255`,0.178`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5693`,0.5241`};
Plota = Graphics3D[{Opacity[0.5],Sphere[p[[1]],u2[[c1]]],Sphere[p[[2]],u2[[c3]]],Sphere[v2,u2[[c2]]]}];
Plotc=Graphics3D[{Tube[{p[[1]],v2},0.02],Tube[{p[[1]],p[[2]]},0.02],Tube[{p[[2]],v2},0.02]}];

Plotb0=Graphics3D[Text[c3,p[[2]],{1,0}]];
Plotb1=Graphics3D[Text[c1,p[[1]],{1,0}]];
Plotb2=Graphics3D[Text[c2,{0,0,0},{1,0}]];
Show[Plota,Plotb0,Plotb1,Plotb2,Plotc,{Axes->Automatic,AxesLabel->{xl,yl,zl},AspectRatio->Automatic,Boxed->False,PlotRange->Automatic, SphericalRegion->True}]

(* rotate p1 around x-axis until the z-comp = 0 *)
T1=ArcTan[p[[1,3]]/p[[1,2]]]
U=p;
T=RotationMatrix[T1,{1,0,0}];
MatrixForm[T]
p=U.T

(* Rotate p1 around z-axis to make y-comp to 0 *)

T2=ArcTan[p[[1,2]]/p[[1,1]]]
U=p;
T=RotationMatrix[T2,{0,0,1}];
MatrixForm[T]
p=Chop[U.T]

(* rotate p2 around x-axis to make z-comp = 0 *)

T3=ArcTan[p[[2,3]]/p[[2,2]]]
U=p;
T=RotationMatrix[T3,{1,0,0}];
MatrixForm[T]
p=Chop[U.T]

Plota = Graphics3D[{Opacity[0.5],Sphere[p[[1]],u2[[c1]]],Sphere[p[[2]],u2[[c3]]],Sphere[v2,u2[[c2]]]}];
Plotc=Graphics3D[{Tube[{p[[1]],v2},0.02],Tube[{p[[1]],p[[2]]},0.02],Tube[{p[[2]],v2},0.02]}];

Plotb0=Graphics3D[Text[c3,p[[2]],{1,0}]];
Plotb1=Graphics3D[Text[c1,p[[1]],{1,0}]];
Plotb2=Graphics3D[Text[c2,{0,0,0},{1,0}]];
Show[Plota,Plotb0,Plotb1,Plotb2,Plotc,{Axes->Automatic,AxesLabel->{xl,yl,zl},AspectRatio->Automatic,Boxed->False,PlotRange->Automatic, SphericalRegion->True}]

(* now reverse the three rotations *)

U=p;
T=RotationMatrix[-T3,{1,0,0}];
MatrixForm[T]
p=U.T

U=p;
T=RotationMatrix[-T2,{0,0,1}];
MatrixForm[T]
p=U.T

U=p;
T=RotationMatrix[-T1,{1,0,0}];
MatrixForm[T]
p=U.T

Plota = Graphics3D[{Opacity[0.5],Sphere[p[[1]],u2[[c1]]],Sphere[p[[2]],u2[[c3]]],Sphere[v2,u2[[c2]]]}];
Plotc=Graphics3D[{Tube[{p[[1]],v2},0.02],Tube[{p[[1]],p[[2]]},0.02],Tube[{p[[2]],v2},0.02]}];

Plotb0=Graphics3D[Text[c3,p[[2]],{1,0}]];
Plotb1=Graphics3D[Text[c1,p[[1]],{1,0}]];
Plotb2=Graphics3D[Text[c2,{0,0,0},{1,0}]];
Show[Plota,Plotb0,Plotb1,Plotb2,Plotc,{Axes->Automatic,AxesLabel->{xl,yl,zl},AspectRatio->Automatic,Boxed->False,PlotRange->Automatic, SphericalRegion->True}]