所以,让我说我有一个坐标网格。我需要知道p0是否位于从p1开始以p2结束的椭圆上。
其他几何对象的示例: - 矩形
function PositiongOnRectangle(posx, posy, x1, y1, x2, y2)
return (posx >= x1 and posy >= y1 and posx <= x2 and posy <= y2)
end
- 圈
function PositionOnCircle(posx, posy, x1, y1, radius)
local distance = math.sqrt((posx - x1)^2 + (posy - y1)^2)
return (radius >= distance)
end
上面的Exmaples在Lua中存在,但是伪代码会这样做。我想用椭圆做同样的事情。
提前致谢!
答案 0 :(得分:1)
对于椭圆,刻在轴对齐的矩形中,由两个顶点p1,p2定义:
PositionOnEllipse(posx, posy, x1, y1, x2, y2)
///center of ellipse coordinates:
mx = (x1+x2)/2
my = (y1+y2)/2
///ellipse semiaxes:
ax = (x1-x2)/2
ay = (y1-y2)/2
////due to ellipse equation
return = (posx-mx)^2/ax^2 + (posy-my)^2/ay^2 <= 1