ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/src/pl3cut.c

This is pl3cut.c in view mode; [Download] [Up]

/* Determines the point of intersection (cx,cy) between the line */
/* joining (sx1,sy1) to (sx2,sy2) and the line joining */
/* (su1,sv1) to (su2,sv2). */

#include "plplot.h"

void pl3cut(sx1,sy1,sx2,sy2,su1,sv1,su2,sv2,cx,cy)
int sx1, sy1, sx2, sy2, su1, sv1, su2, sv2, *cx, *cy;
{
      int x21, y21, u21, v21, yv1, xu1, a, b;
      double fa, fb;

      x21 = sx2 - sx1;
      y21 = sy2 - sy1;
      u21 = su2 - su1;
      v21 = sv2 - sv1;
      yv1 = sy1 - sv1;
      xu1 = sx1 - su1;

      a = x21 * v21 - y21 * u21;
      fa = (double)a;
      if (a == 0) {
        if (sx2 < su2) {
          *cx = sx2;
          *cy = sy2;
        }
        else {
          *cx = su2;
          *cy = sv2;
        }
        return;
      }
      else {
        b = yv1 * u21 - xu1 * v21;
        fb = (double)b;
        *cx = (int)(sx1 + (fb * x21)/ fa + .5);
        *cy = (int)(sy1 + (fb * y21)/ fa + .5);
      }
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.