Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static std::array<int, 3> cross(const std::array<int, 3> &a,
- const std::array<int, 3> &b)
- {
- std::array<int, 3> result;
- result[0] = a[1] * b[2] - a[2] * b[1];
- result[1] = a[2] * b[0] - a[0] * b[2];
- result[2] = a[0] * b[1] - a[1] * b[0];
- return result;
- }
- static bool get_intersection(const cv::Vec4i &line_a,
- const cv::Vec4i &line_b, cv::Point &intersection)
- {
- std::array<int, 3> pa{ { line_a[0], line_a[1], 1 } };
- std::array<int, 3> pb{ { line_a[2], line_a[3], 1 } };
- std::array<int, 3> la = cross(pa, pb);
- pa[0] = line_b[0], pa[1] = line_b[1], pa[2] = 1;
- pb[0] = line_b[2], pb[1] = line_b[3], pb[2] = 1;
- std::array<int, 3> lb = cross(pa, pb);
- std::array<int, 3> inter = cross(la, lb);
- if (inter[2] == 0) return false; // two lines are parallel
- else {
- intersection.x = inter[0] / inter[2];
- intersection.y = inter[1] / inter[2];
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement