Reputation: 646
I want to calculate the points defining two crossing circles in Python. See the plot below of the points I want to calculate.
I have the following algorithm to calculate the point defining one circle :
def get_circle_points(x_center, y_center, radius, n=20):
xpoints = []
ypoints = []
for i in range(0, n+1):
x = math.cos(2*math.pi/n*i) * radius + x_center
y = math.sin(2*math.pi/n*i) * radius + y_center
xpoints.append(x)
ypoints.append(y)
return xpoints, ypoints
One important limitation is that I can't import numpy
, only pure Python answer are ok.
Upvotes: 0
Views: 100
Reputation: 80187
Very simple approach (with some excessive calculations):
Get start angle as
sa = atan2(yc2-yc1, xc2-xc1)
Generate the first circle points in angle range sa..sa + 2*Pi
Check - if point (px,py) is outside the second circle, add it to result list (px-cx2)^2+(py-cy2)^2 > r2^2
Generate the second circle points in angle range sa - Pi..sa + Pi
Check - if point (px,py) is outside the first circle, add it to result list (px-cx1)^2+(py-cy1)^2 > r1^2
More effective approach - calculate intersection points angles and scan only needed angle ranges.
Upvotes: 1