另一种选择是将所有内容都放入二维旋转椭圆的方程中,看看结果是否小于一个。
如果以下不等式为真,则点在椭圆内
其中 (xp,yp) 是点坐标,(x0, y0) 是椭圆的中心。
我实现了一个小型 Mathematica 程序,证明这确实有效:
它在行动:
这里是代码:
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}]