Guest User

Untitled

a guest
May 9th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. struct Point
  2. {
  3. int x, y;
  4. };
  5. typedef struct
  6. {
  7. Point p;
  8. Point d;
  9. } Line, Rect;
  10. Point findIntersection(Line l1, Line l2)
  11. {
  12. int T1, T2;
  13. 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);
  14. T1 = (l1.p.x+l1.d.x*T2-l2.p.x)/l2.d.x;
  15. if (T1>0 && 0<T2<1) {
  16. return {l2.p.x+l2.d.x*T1, l2.p.y+l2.d.y*T1};
  17. }
  18. }
  19. Point getRectPoint(Rect r, int n)
  20. {
  21. switch (n) {
  22. case 0: return {r.p.x, r.d.y};
  23. case 1: return r.d;
  24. case 2: return r.p;
  25. case 3: return {r.d.x, r.p.y};
  26. }
  27. }
  28. int main()
  29. {
  30. Point p1 = {0, 0};
  31. Point p2 = {10, 10};
  32. Line l1 = {p1, p2};
  33. Line l2 = {p2, p1};
  34. findIntersection(l1, l2);
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment