7
#define SMALL 0.0000000001
10
subPt (pointf a, pointf b)
30
dot (pointf a, pointf b)
32
return (a.x*b.x + a.y*b.y);
36
scale (double c, pointf a)
46
* Computes intersection of lines a-b and c-d, returning intersection
48
* Returns 0 if no intersection (lines parallel), 1 otherwise.
51
intersect (pointf a, pointf b, pointf c, pointf d, pointf* x)
53
pointf mv = subPt (b,a);
54
pointf lv = subPt (d,c);
55
pointf ln = perp (lv);
56
double lc = -dot(ln,c);
57
double dt = dot(ln,mv);
59
if (fabs(dt) < SMALL) return 0;
61
*x = subPt(a,scale((dot(ln,a)+lc)/dt,mv));
71
int ax, ay, bx, by, cx, cy, dx, dy;
75
fgets (buf, 1024, stdin);
76
sscanf (buf, "%d %d %d %d", &ax, &ay, &bx, &by);
78
fgets (buf, 1024, stdin);
79
sscanf (buf, "%d %d %d %d", &cx, &cy, &dx, &dy);
88
if (intersect (a,b,c,d,&x))
89
printf ("(%f,%f)\n", x.x,x.y);
91
printf ("no intersection\n");