1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
void cross(double a[2], double b[2], double c[2])
{
c[0]=a[1]*b[2]-a[2]*b[1];
c[1]=a[2]*b[0]-a[0]*b[2];
c[2]=a[0]*b[1]-a[1]*b[0];
}
double dp(double a[2], double b[2])
{
return(a[0]*b[0]+a[1]*b[1]+a[2]*b[2]);
}
double Sdihedral(int a1, int a2, int a3, int a4, double mydat[][82][2], int mytime){
double v1[2], v2[2], v3[2];
double size;
double v2v1[2];
double cp23[2],cp12[2],dp1,dp2;
double retval;
int myi;
for (myi=0;myi<3;myi++){
v1[myi]=mydat[mytime][a2][myi]-mydat[mytime][a1][myi];
v2[myi]=mydat[mytime][a3][myi]-mydat[mytime][a2][myi];
v3[myi]=mydat[mytime][a4][myi]-mydat[mytime][a3][myi];
}
size=pow((v2[0]*v2[0]+v2[1]*v2[1]+v2[2]*v2[2]),0.5);
v2v1[0]=v1[0]*size;
v2v1[1]=v1[1]*size;
v2v1[2]=v1[2]*size;
cross(v2,v2,cp23);
cross(v1,v2,cp12);
dp1=dp(v2v1,cp23);
dp2=dp(cp12,cp23);
retval=57.2957795*atan2(dp1,dp2);
if (retval<0){
retval=retval+360;
}
if (retval>360){
retval=retval-360;
}
return (retval);
}
|