(* 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 7.3.2013 *)
Clear[T1,T2,U,V,T,P,p,q,r];
rad=57.2957795;
P=2;
p={{0.8910058089999993`,-1.2609385707599998`,2.215514762399999`},
{-1.3556894324000002`,-1.02001740302`,-0.6789785517999993`}};
q=Table[0,{P},{3}];
r=q; s=q;

(* rotate p1 around x-axis until the z-comp = 0 *)

T1=-ArcTan[p[[1,3]]/p[[1,2]]]*rad      (*60.35405486;*)

U=Table[0,{P},{4}];
V=U;
For[i=1,i<P+1,i++,
U[[i,1]]=p[[i,1]];
U[[i,2]]=p[[i,2]];
U[[i,3]]=p[[i,3]];
U[[i,4]]=1]
MatrixForm[U]

T2=T1/rad;
T=Table[0,{4},{4}];
T[[1,1]]=1.0;
T[[4,4]]=T[[1,1]];
T[[2,2]]=Cos[T2];
T[[3,3]]=T[[2,2]];
T[[2,3]]=Sin[T2];
T[[3,2]]=-T[[2,3]];
MatrixForm[T]

V=U.T;
For[i=1,i<P+1,i++,
q[[i,1]]=V[[i,1]];
q[[i,2]]=V[[i,2]];
q[[i,3]]=V[[i,3]]];
q

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

Clear[T1,T2,U,V,T];
T1=180+ArcTan[q[[1,2]]/q[[1,1]]]*rad     (* 109.26548;*)

U=Table[0,{P},{4}];
V=U;

For[i=1,i<P+1,i++,
U[[i,1]]=q[[i,1]];
U[[i,2]]=q[[i,2]];
U[[i,3]]=q[[i,3]];
U[[i,4]]=1]
MatrixForm[U]

T2=T1/rad;
T=Table[0,{4},{4}];
T[[1,1]]=Cos[T2];
T[[1,2]]=-Sin[T2];
T[[2,1]]=-T[[1,2]];
T[[4,4]]=1;
T[[2,2]]=T[[1,1]];
T[[3,3]]=T[[4,4]];
MatrixForm[T]

V=U.T;
For[i=1,i<P+1,i++,
r[[i,1]]=V[[i,1]];
r[[i,2]]=V[[i,2]];
r[[i,3]]=V[[i,3]]];
r

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

Clear[T1,T2,U,V,T];
T1=-ArcTan[r[[2,3]]/r[[2,2]]]*rad  (*44.323845;*)

U=Table[0,{P},{4}];
V=U;

For[i=1,i<P+1,i++,
U[[i,1]]=r[[i,1]];
U[[i,2]]=r[[i,2]];
U[[i,3]]=r[[i,3]];
U[[i,4]]=1]
MatrixForm[U]

T2=T1/rad;
T=Table[0,{4},{4}];
T[[1,1]]=1.0;
T[[4,4]]=T[[1,1]];
T[[2,2]]=Cos[T2];
T[[3,3]]=T[[2,2]];
T[[2,3]]=Sin[T2];
T[[3,2]]=-T[[2,3]];
MatrixForm[T]

V=U.T;
For[i=1,i<P+1,i++,
s[[i,1]]=V[[i,1]];
s[[i,2]]=V[[i,2]];
s[[i,3]]=V[[i,3]]];
s

c1=20; c2=21; c3=51;
v2={0,0,0,1};
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[s[[1]],u2[[c1]]],Sphere[s[[2]],u2[[c3]]],Sphere[Take[v2,3],u2[[c2]]]}];
Plotc=Graphics3D[{Tube[{s[[1]],Take[v2,3]},0.02],Tube[{s[[1]],s[[2]]},0.02],Tube[{s[[2]],Take[v2,3]},0.02]}];

Plotb0=Graphics3D[Text[c3,s[[2]],{1,0}]];
Plotb1=Graphics3D[Text[c1,s[[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 add O lone pairs perpendicular to COH plane and retransform into molecular skeleton *)