2 回答

TA贡献1817条经验 获得超14个赞
我最终使用了这个答案中的椭圆方程:
并创建了一个 in_ellipse 函数
然后我使用了中值定理,对点进行了很好的估计
def in_ellipse(point, ellipse):
return true if point in ellipse
return false
dot_a = ellipse_center
dot_b = dot
for i in range(20):
center_point = ((dot_b.y - dot_a.y)/2, (dot_b.x - dot_a.x)/2)
if in_ellipse(center_point):
dot_a = center_point
else:
dot_b = center_point
return center_point
该系统在小数点后以 7 (2^20) 位分辨率给出点,您可以增加范围以获得更好的分辨率。

TA贡献1829条经验 获得超6个赞
让椭圆中心为(0,0) (否则只需减去中心坐标),半轴为a, b,旋转角度为theta。我们可以建立仿射变换将椭圆变换为圆并将相同的变换应用于点 P。
1) 旋转 -theta
px1 = px * Cos(theta) + py * Sin(theta)
py1 = -px * Sin(theta) + py * Cos(theta)
2) 沿 OY 轴按a/b时间延伸(或收缩)
px2 = px1
py2 = py1 * a / b
3) 找到交点
plen = hypot(px2, py2) (length of p2 vector)
if (a > plen), then segment doesn't intersect ellipse - it fully lies inside
ix = a * px2 / plen
iy = a * py2 / plen
4)进行向后收缩
ix2 = ix
iy2 = iy * b / a
5) 反向旋转
ixfinal = ix2 * Cos(theta) - iy2 * Sin(theta)
iyfinal = ix2 * Sin(theta) + iy2 * Cos(theta)
添加回答
举报