-
bool CC3PDlg::calCircleCenter(PD3Point p1,PD3Point p2,double &radium)
-
-
-
-
- {
-
double dPx,dQx,dRx;
-
double dPy,dQy,dRy;
-
double dPz,dQz,dRz;
-
double dX0,dY0,dZ0;
-
double dR;
-
- dPx=p1[0].x;
- dQx=p1[1].x;
- dRx=p1[2].x;
-
- dPy=p1[0].y;
- dQy=p1[1].y;
- dRy=p1[2].y;
-
- dPz=p1[0].z;
- dQz=p1[1].z;
- dRz=p1[2].z;
-
-
-
double pi,pj,pk;
-
double x1=dQx-dPx;
-
double x2=dRx-dPx;
-
-
double y1=dQy-dPy;
-
double y2=dRy-dPy;
-
-
double z1=dQz-dPz;
-
double z2=dRz-dPz;
-
- pi=y1*z2-z1*y2;
- pj=z1*x2-x1*z2;
- pk=x1*y2-y1*x2;
-
-
if((pi==0)&&(pj==0)&&(pk==0))
- {
-
return FALSE;
- }
-
-
-
double dMx,dMy,dMz;
-
- dMx=(dPx+dQx)/2;
- dMy=(dPy+dQy)/2;
- dMz=(dPz+dQz)/2;
-
-
-
double dMi,dMj,dMk;
- dMi=pj*z1-pk*y1;
- dMj=pk*x1-pi*z1;
- dMk=pi*y1-pj*x1;
-
-
-
double dNx,dNy,dNz;
-
- dNx=(dPx+dRx)/2;
- dNy=(dPy+dRy)/2;
- dNz=(dPz+dRz)/2;
-
-
-
double dNi,dNj,dNk,ds;
-
- dNi=pj*z2-pk*y2;
- dNj=pk*x2-pi*z2;
- dNk=pi*y2-pj*x2;
-
-
-
- ds=pi*pi+pj*pj+pk*pk;
- ds=sqrt(ds);
-
-
if(ds==0)
- {
- p2[1].x=0;
- p2[1].y=0;
- p2[1].z=0;
- }
-
else
- {
- p2[1].x=pi/ds;
- p2[1].y=pj/ds;
- p2[1].z=pk/ds;
- }
-
-
-
-
-
-
-
-
double tm,tn;
- tn=((dMy-dNy)*dMi+dMj*(dNx-dMx))/(dNj*dMi-dMj*dNi);
-
tm=(dNx+dNi*tn-dMx)/dMi;
-
-
dX0=dMx+dMi*tm;
-
dY0=dMy+dMj*tm;
-
dZ0=dMz+dMk*tm;
-
- p2[0].x=dX0;
- p2[0].y=dY0;
- p2[0].z=dZ0;
-
-
-
- dR=(dX0-dPx)*(dX0-dPx)+(dY0-dPy)*(dY0-dPy)+(dZ0-dPz)*(dZ0-dPz);
- dR=sqrt(dR);
-
- radium=dR;
-
return TRUE;
-
- }