MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / get_intersection

Function get_intersection

lib/matplotlib/bezier.py:116–146  ·  view source on GitHub ↗

Return the intersection between the line through (*cx1*, *cy1*) at angle *t1* and the line through (*cx2*, *cy2*) at angle *t2*.

(cx1, cy1, cos_t1, sin_t1,
                     cx2, cy2, cos_t2, sin_t2)

Source from the content-addressed store, hash-verified

114
115
116def get_intersection(cx1, cy1, cos_t1, sin_t1,
117 cx2, cy2, cos_t2, sin_t2):
118 """
119 Return the intersection between the line through (*cx1*, *cy1*) at angle
120 *t1* and the line through (*cx2*, *cy2*) at angle *t2*.
121 """
122
123 # line1 => sin_t1 * (x - cx1) - cos_t1 * (y - cy1) = 0.
124 # line1 => sin_t1 * x + cos_t1 * y = sin_t1*cx1 - cos_t1*cy1
125
126 line1_rhs = sin_t1 * cx1 - cos_t1 * cy1
127 line2_rhs = sin_t2 * cx2 - cos_t2 * cy2
128
129 # rhs matrix
130 a, b = sin_t1, -cos_t1
131 c, d = sin_t2, -cos_t2
132
133 ad_bc = a * d - b * c
134 if abs(ad_bc) < 1e-12:
135 raise ValueError("Given lines do not intersect. Please verify that "
136 "the angles are not equal or differ by 180 degrees.")
137
138 # rhs_inverse
139 a_, b_ = d, -b
140 c_, d_ = -c, a
141 a_, b_, c_, d_ = (k / ad_bc for k in [a_, b_, c_, d_])
142
143 x = a_ * line1_rhs + b_ * line2_rhs
144 y = c_ * line1_rhs + d_ * line2_rhs
145
146 return x, y
147
148
149def get_normal_points(cx, cy, cos_t, sin_t, length):

Callers 3

connectMethod · 0.85
connectMethod · 0.85
get_parallelsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…