home *** CD-ROM | disk | FTP | other *** search
- /* 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)
- PLINT sx1, sy1, sx2, sy2, su1, sv1, su2, sv2, *cx, *cy;
- {
- PLINT x21, y21, u21, v21, yv1, xu1, a, b;
- PLFLT 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 = (PLFLT)a;
- if (a == 0) {
- if (sx2 < su2) {
- *cx = sx2;
- *cy = sy2;
- }
- else {
- *cx = su2;
- *cy = sv2;
- }
- return;
- }
- else {
- b = yv1 * u21 - xu1 * v21;
- fb = (PLFLT)b;
- *cx = (PLINT)(sx1 + (fb * x21)/ fa + .5);
- *cy = (PLINT)(sy1 + (fb * y21)/ fa + .5);
- }
- }
-