小智 10
圆的方程是(xh)^ 2 +(y -k)^ 2 = r ^ 2.哪里:
x = x-coordinate
y = y-coordinate
h = x-coordinate of the center point
k = y-coordinate of the center point
r = radius
Run Code Online (Sandbox Code Playgroud)
因为从中心到圆周上的点在x轴上的距离,y轴和半径形成直角三角形,其中x距离是基部,y距离是高度,r是斜边那个直角三角形.对于具有中心(0,0)的圆,圆的方程是x ^ 2 + y ^ 2 = r ^ 2(这是毕达哥拉斯定理).
您还可以使用标识cos theta = y/r => y = r*cos theta和sin theta = x/y => x = r*sin theta并在θ上从0到360度迭代
因此,给定中心点(h,k)和半径r,您可以找到位于圆周上的点(x,y).
然后你可以有一个功能来检查某个点是否位于圆周内.你到底需要什么?