Created
January 23, 2013 15:44
-
-
Save mrklein/4608371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def point_on_arc(radius, start_x, start_y, end_x, end_y): | |
""" | |
Returns set of possible points on arc given by start and end points and | |
circle radius. | |
Return value is dictionary with keys 'center' and 'points'. | |
Center is associated with list of tuples with possible center coordinates. | |
Points is associated with list of tuples with possible points on the arc. | |
""" | |
X = start_x - end_x | |
Y = start_y - end_y | |
D = X ** 2 + Y ** 2 | |
Q = sqrt(4 * radius ** 2 / D - 1) | |
K1 = 0.5 * (Y + X * Q) | |
K2 = 0.5 * (Y - X * Q) | |
H1 = 0.5 * (X + Y * Q) | |
H2 = 0.5 * (X - Y * Q) | |
x01, y01 = H1 + end_x, K1 + end_y | |
x02, y02 = H2 + end_x, K2 + end_y | |
xc1 = 0.5 * (start_x + end_x) | |
Q1 = sqrt(radius ** 2 - (xc1 - x01) ** 2) | |
Q2 = sqrt(radius ** 2 - (xc1 - x02) ** 2) | |
return { | |
'center': [ | |
(x01, y01), | |
(x02, y02) | |
], | |
'points': [ | |
(xc1, y01 + Q1), | |
(xc1, y01 - Q1), | |
(xc1, y02 + Q2), | |
(xc1, y02 - Q2) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment