home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / CVPOLR.C < prev    next >
Encoding:
Text File  |  1984-06-01  |  733 b   |  35 lines

  1.       cvpolr(x,y,r,ang,iflag)
  2.  
  3.       /*subroutine to convert polar coordinates to rectangular*/
  4.       /*coordinates or rectangular coordinates to polar*/
  5.       /*coordinates.*/
  6.  
  7.  
  8.       int *iflag;
  9.       float *x,*y,*r,*ang;
  10.  
  11.  
  12.     {
  13.  
  14.       extern double sqrt(),atan(),cos(),sin();
  15.  
  16.       if (*iflag <  1 || *iflag >  2)
  17.          *iflag=-99;                         /* error */
  18.  
  19.       else if (*iflag == 2)
  20.         {
  21.         *x = (*r)*cos(*ang);                   /* polar to rect */
  22.         *y = (*r)*sin(*ang);
  23.         }
  24.  
  25.       else                                      /* rect to polar */
  26.         {
  27.         *r = sqrt(((*x)*(*x)) + ((*y)*(*y)));
  28.         *ang = atan((*y)/(*x));
  29.         }
  30.  
  31.     }
  32.  
  33.  
  34.  
  35.