home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / pl3cut.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  918 b   |  40 lines

  1. /* Determines the point of intersection (cx,cy) between the line */
  2. /* joining (sx1,sy1) to (sx2,sy2) and the line joining */
  3. /* (su1,sv1) to (su2,sv2). */
  4.  
  5. #include "plplot.h"
  6.  
  7. void pl3cut(sx1,sy1,sx2,sy2,su1,sv1,su2,sv2,cx,cy)
  8. PLINT sx1, sy1, sx2, sy2, su1, sv1, su2, sv2, *cx, *cy;
  9. {
  10.       PLINT x21, y21, u21, v21, yv1, xu1, a, b;
  11.       PLFLT fa, fb;
  12.  
  13.       x21 = sx2 - sx1;
  14.       y21 = sy2 - sy1;
  15.       u21 = su2 - su1;
  16.       v21 = sv2 - sv1;
  17.       yv1 = sy1 - sv1;
  18.       xu1 = sx1 - su1;
  19.  
  20.       a = x21 * v21 - y21 * u21;
  21.       fa = (PLFLT)a;
  22.       if (a == 0) {
  23.         if (sx2 < su2) {
  24.           *cx = sx2;
  25.           *cy = sy2;
  26.         }
  27.         else {
  28.           *cx = su2;
  29.           *cy = sv2;
  30.         }
  31.         return;
  32.       }
  33.       else {
  34.         b = yv1 * u21 - xu1 * v21;
  35.         fb = (PLFLT)b;
  36.         *cx = (PLINT)(sx1 + (fb * x21)/ fa + .5);
  37.         *cy = (PLINT)(sy1 + (fb * y21)/ fa + .5);
  38.       }
  39. }
  40.