MCPcopy Create free account
hub / github.com/davisking/dlib / intersect

Function intersect

dlib/geometry/line.h:92–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90
91 template <typename T>
92 inline dpoint intersect(
93 const std::pair<vector<T,2>,vector<T,2>>& a,
94 const std::pair<vector<T,2>,vector<T,2>>& b
95 )
96 {
97 // convert to homogeneous coordinates
98 dlib::vector<double,3> a1 = a.first;
99 dlib::vector<double,3> a2 = a.second;
100 dlib::vector<double,3> b1 = b.first;
101 dlib::vector<double,3> b2 = b.second;
102 a1.z() = 1;
103 a2.z() = 1;
104 b1.z() = 1;
105 b2.z() = 1;
106
107 // find lines between pairs of points.
108 auto l1 = a1.cross(a2);
109 auto l2 = b1.cross(b2);
110
111 // find intersection of the lines.
112 auto p = l1.cross(l2);
113
114 if (p.z() != 0)
115 return p/p.z();
116 else
117 return dpoint(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
118 }
119
120// ----------------------------------------------------------------------------------------
121

Callers 2

test_lineFunction · 0.50

Calls 2

zMethod · 0.80
crossMethod · 0.45

Tested by 1

test_lineFunction · 0.40