Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何让 Turtle 识别圆圈?
我有一个绘制几个圆圈的函数,我将在其中放置点。取决于点是否落在圆圈内,取决于颜色是否会改变。
我发现的最大问题是如何检查点是否在圆圈内。有谁知道如何计算圆内的坐标,或者他们是一种可以检查圆坐标的方法吗?
对于圆心(x,y)和半径的圆,如果r一个点(x1, y1)在圆内
(x,y)
r
(x1, y1)
(x1-x)² + (y1-y)² <= r²
计算到圆心的(欧几里得)距离,
sqrt((x - center_x) ** 2 + (y - center_y) ** 2)
检查结果是否小于半径。
要检查坐标是否位于圆上,您可以使用圆的方程
a² + b² = r²
所以要检查点是否在圆圈内:
a² + b² <= r²