Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. static std::array<int, 3> cross(const std::array<int, 3> &a,
  2. const std::array<int, 3> &b)
  3. {
  4. std::array<int, 3> result;
  5. result[0] = a[1] * b[2] - a[2] * b[1];
  6. result[1] = a[2] * b[0] - a[0] * b[2];
  7. result[2] = a[0] * b[1] - a[1] * b[0];
  8. return result;
  9. }
  10.  
  11. static bool get_intersection(const cv::Vec4i &line_a,
  12. const cv::Vec4i &line_b, cv::Point &intersection)
  13. {
  14. std::array<int, 3> pa{ { line_a[0], line_a[1], 1 } };
  15. std::array<int, 3> pb{ { line_a[2], line_a[3], 1 } };
  16. std::array<int, 3> la = cross(pa, pb);
  17. pa[0] = line_b[0], pa[1] = line_b[1], pa[2] = 1;
  18. pb[0] = line_b[2], pb[1] = line_b[3], pb[2] = 1;
  19. std::array<int, 3> lb = cross(pa, pb);
  20. std::array<int, 3> inter = cross(la, lb);
  21. if (inter[2] == 0) return false; // two lines are parallel
  22. else {
  23. intersection.x = inter[0] / inter[2];
  24. intersection.y = inter[1] / inter[2];
  25. return true;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement