home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 25 / CD_ASCQ_25_1095.iso / dos / graphic / link / link5.c < prev    next >
C/C++ Source or Header  |  1995-07-12  |  1KB  |  49 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. void main(int argc, char **argv){
  6.     if(argc==4){
  7.         int
  8.             i,            /*        loop counter        */
  9.             iS;            /*        the number of spheres    */
  10.         float
  11.             fL,            /*        length of link        */
  12.             fW,            /*        width of link        */
  13.             fP,            /*        Pi        */
  14.             fPh,            /*        Phi    */
  15.             fTh,            /*        Theta        */
  16.             fX,            /*        X coord        */
  17.             fY,            /*        Y coord        */
  18.             fZ,            /*        Z coord        */
  19.             fTZ;            /*        temp Z coord  */
  20.         fL=atof(argv[1])/2;
  21.         fW=atof(argv[2])/2;
  22.         iS=floor(atoi(argv[3])/2);
  23.         fP=3.141592654;
  24.         printf("R = %f\n\n",fL/10);
  25.         for(i=0;i<iS;i++){
  26.             fPh=fP*i/iS;
  27.             fTh=(1-cos(fPh))*(fP/4);
  28.             fX=fW*cos(fTh)*sin(fPh);
  29.             fY=fW*sin(fTh)*sin(fPh);
  30.             fTZ=cos(fPh);
  31. /*            fZ=fL*sqrt(fabs(fTZ))*fTZ/fabs(fTZ);*/
  32. /*            fZ=fL*fTZ*(1+cos(fP*fTZ/2)*2/3);*/
  33.             fZ=fL*fTZ*(1+fTZ*(sin(fP*fTZ))*1/8);
  34.             printf("%f, %f, %f, R\n",fX,fY,fZ);
  35.         }
  36.         for(i=0;i<iS;i++){
  37.             fPh=fP*i/iS;
  38.             fTh=-(1-cos(fPh))*(fP/4)-fP/2;
  39.             fX=fW*cos(fTh)*sin(fPh);
  40.             fY=fW*sin(fTh)*sin(fPh);
  41.             fTZ=cos(fPh);
  42. /*            fZ=fL*(-sqrt(fabs(fTZ))*fTZ/fabs(fTZ));*/
  43. /*            fZ=-fL*fTZ*(1+cos(fP*fTZ/2)*2/3);*/
  44.             fZ=-fL*fTZ*(1+fTZ*(sin(fP*fTZ))*1/8);
  45.             printf("%f, %f, %f, R\n",fX,fY,fZ);
  46.         }
  47.     }
  48.     else printf("Usage: link(length) (width) (spheres) > (filename)\n");
  49. }