Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Point
- {
- int x, y;
- };
- typedef struct
- {
- Point p;
- Point d;
- } Line, Rect;
- Point findIntersection(Line l1, Line l2)
- {
- int T1, T2;
- T2 = (l2.d.x*(l1.p.y-l2.p.y) + l2.d.y*(l2.p.x-l1.p.x))/(l1.d.x*l2.d.y - l1.d.y*l2.d.x);
- T1 = (l1.p.x+l1.d.x*T2-l2.p.x)/l2.d.x;
- if (T1>0 && 0<T2<1) {
- return {l2.p.x+l2.d.x*T1, l2.p.y+l2.d.y*T1};
- }
- }
- Point getRectPoint(Rect r, int n)
- {
- switch (n) {
- case 0: return {r.p.x, r.d.y};
- case 1: return r.d;
- case 2: return r.p;
- case 3: return {r.d.x, r.p.y};
- }
- }
- int main()
- {
- Point p1 = {0, 0};
- Point p2 = {10, 10};
- Line l1 = {p1, p2};
- Line l2 = {p2, p1};
- findIntersection(l1, l2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment