另一种选择是将所有内容都放入二维旋转椭圆的方程中,然后查看结果是否小于1。
因此,如果以下不等式成立,则点位于椭圆内:
![ellipse equation](https://istack.dev59.com/J0p9k.webp)
其中(xp,yp)为点坐标,(x0,y0)为椭圆中心。
我编写了一个小的Mathematica程序来演示这确实有效:
![Manipulate screen shot](https://istack.dev59.com/8Gtto.webp)
它的运行效果如下:
![Animation](https://istack.dev59.com/ek3cQ.gif)
这是代码:
ellipse[x_, y_, a_, b_, \[Alpha]_, x0_: 0, y0_: 0] :=
(((x - x0)*Cos[\[Alpha]] + (y - y0)*Sin[\[Alpha]])/a)^2
+ (((x - x0)*Sin[\[Alpha]] - (y - y0)*Cos[\[Alpha]])/b)^2;
Manipulate[
RegionPlot[
ellipse[x, y, a, b, \[Alpha] \[Degree], Sequence @@ pos] < 1, {x, -5, 5}, {y, -5, 5},
PlotStyle -> If[ellipse[Sequence @@ p, a, b, \[Alpha] \[Degree], Sequence @@ pos] <= 1, Orange, LightBlue],
PlotPoints -> 25]
, {{a, 2}, 1, 5, Appearance -> "Labeled"}
, {{b, 4}, 2, 5, Appearance -> "Labeled"}
, {\[Alpha], 0, 180, Appearance -> "Labeled"}
, {{p, {3, 1}}, Automatic, ControlType -> Locator}
, {{pos, {0, 0}}, Automatic, ControlType -> Locator}]