点和椭圆(旋转)位置测试:算法 [英] Point and ellipse (rotated) position test: algorithm

查看:500
本文介绍了点和椭圆(旋转)位置测试:算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试一个点P = [XP,YP]是内/外的中心C = [X,Y],A,B,和Phi(旋转角度)给出了一些旋转的椭圆形?

How to test if a point P = [xp,yp] is inside/outside some rotated ellipse given by the centre C=[x,y], a, b, and phi ( angle of rotation)?

在这个时刻我使用以下解决方案:旋转椭圆点的角度-phi,然后共同测试点的位置和非旋转椭圆。

At this moment I am using the following solution: rotate ellipse and point by the angle -phi and then the common test for a position of the point and "non rotated" ellipse.

但也有很多测试点(千)的,我觉得这个解决方案是缓慢的。是否有任何直接,更有效的方式来获得旋转的椭圆的位置,点?

But there are a lot of tested points (thousands) and I find this solution as slow. Is there any direct and more efficient way to get a position of the rotated ellipse and point?

我并不需要一个code,但该算法。感谢您的帮助。

I do not need a code but the algorithm. Thanks for your help.

推荐答案

另一种选择是只是抛出一切入方程用于2D旋转椭圆而看到如果结果是小于1。

Another option is just to throw everything into the equation for a 2D rotated ellipse and see if the result is less than one.

因此​​,一个点是椭圆内如果满足以下不等式为真

So a point is inside the ellipse if the following inequality is true

其中(XP,YP)是该点的坐标和(X0,Y0)是椭圆的中心

Where (xp,yp) are the point coordinates and (x0, y0) is the center of the ellipse.

我实现了一个小型的数学的程序证明了这确实是工作原理:

I implemented a small Mathematica program demonstrating that this indeed works:

这是在行动:

这里是code:

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}]

这篇关于点和椭圆(旋转)位置测试:算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆