home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / general.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  1.3 KB  |  80 lines

  1. #define halfpi 1.57079632679489661923
  2. #define pi 3.14159265358979323846
  3. #include <math.h>
  4. #include "all.h"
  5. showpcode(long *p)
  6. {
  7.     union {long l; short s[2];} bth;
  8.     int i;
  9.  
  10.     gprint("GP> ");
  11.     for (i=0;i<4;i++) {
  12.         bth.l = *(p++);
  13.         gprint("%x %x  ",bth.s[0],bth.s[1]);
  14.     }
  15.     gprint("\n");
  16. }
  17. polar_xy(double r, double angle, double *dx, double *dy)
  18. {
  19.     *dx = r*cos(angle*3.14159265/180);
  20.     *dy = r*sin(angle*3.14159265/180);
  21. }
  22. xy_polar(double dx,double dy,double *radius,double *angle)
  23. {
  24.     if (dx==0 && dy==0) {
  25.         gprint("Cannot work out angle of zero length vector\n");
  26.         return;
  27.     }
  28.     if (dx==0) {
  29.         *angle = 90;
  30.         if (dy<0) *angle = -90;
  31.     } else {
  32.         *angle = myatan2(dy,dx)*180/pi;
  33.     }
  34.     *radius = sqrt(dx*dx + dy*dy);
  35. }
  36. ncpy(char *d, char *s, int n)
  37. {
  38.     strncpy(d,s,n);
  39.     *(d+n) = 0;
  40. }
  41. ncat(char *d, char *s, int n)
  42. {
  43.     int i;
  44.     i = strlen(d);
  45.     strncat(d,s,n);
  46.     *(d+i+n) = 0;
  47. }
  48. #ifdef VAXC
  49. double myatan2(double y, double x)
  50. {
  51.     static double one,test,xx,yy,zero,at2;
  52.     zero = 0;
  53.     one = 1;
  54.     xx = fabs(x);
  55.     yy = fabs(y);
  56.     if (x==0) {
  57.         at2 = halfpi;
  58.     } else {
  59.         if (yy<=xx) {
  60.             at2 = fabs(atan(yy/xx));
  61.         } else {
  62.             test = one + (xx/yy);
  63.             if (test!=one) {
  64.                 at2 = fabs(atan(yy/xx));
  65.             } else {
  66.                 at2 = halfpi;
  67.             }
  68.         }
  69.         if (x<zero) at2 = pi - at2;
  70.     }
  71.     if (y<0) at2 = -at2;
  72.     return at2;
  73. }
  74. #else
  75. double myatan2(double y, double x)
  76. {
  77.     return atan2(y,x);
  78. }
  79. #endif
  80.