Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Point inside an ellipse (given that I know minor and major axis of the ellipse)

Subject: Point inside an ellipse (given that I know minor and major axis of the ellipse)

From: Camille Couzi

Date: 8 Dec, 2010 12:47:04

Message: 1 of 4

Hi!
I suppose that this is recurrent and easye question,but how can I know if a couple of points (x,y) is inside and ellipse defined by major and minor axis?
I have read some solutions using inpolygon, but I don't really know how to define the polygon so that it will be my ellipse...
If somebody can help me I will be very very greatfull.
Thanks in advance!

Subject: Point inside an ellipse (given that I know minor and major axis of the ellipse)

From: Matt J

Date: 8 Dec, 2010 14:37:18

Message: 2 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <idnuo8$8s3$1@fred.mathworks.com>...
> Hi!
> I suppose that this is recurrent and easye question,but how can I know if a couple of points (x,y) is inside and ellipse defined by major and minor axis?
=======

Well, for an unrotated ellipse centered at the origin with major and minor axis lengths a and b, the inside of the ellipse are points satisfying

(x/a)^2+(y/b)^2<=1

So, you need simply test of your given (x,y) satisfy this inequality. For rotated/translated ellipses, apply an appropriate coordinate transformation to the above.

Subject: Point inside an ellipse (given that I know minor and major axis of the ellipse)

From: Bruno Luong

Date: 8 Dec, 2010 19:44:07

Message: 3 of 4

To generalize Matt's formula, for non-aligned ellipse do this:

% two semi-axis
ax1 = [4; 1];
ax2 = [-0.5 2];

W = [ax1(:) ax2(:)];

x=linspace(-5,5);
y=linspace(-5,5);
[X Y] = meshgrid(x,y);
in = reshape(sum(( [X(:) Y(:)]/W.').^2,2)<1, size(X));

clf
hold on
imagesc(x,y,in)
axis equal
set(gca, 'YDir', 'normal')
plot(W(1,:),W(2,:),'og')

Subject: Point inside an ellipse (given that I know minor and major axis of the ellipse)

From: Roger Stafford

Date: 8 Dec, 2010 21:30:22

Message: 4 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <idnuo8$8s3$1@fred.mathworks.com>...
> Hi!
> I suppose that this is recurrent and easye question,but how can I know if a couple of points (x,y) is inside and ellipse defined by major and minor axis?
> I have read some solutions using inpolygon, but I don't really know how to define the polygon so that it will be my ellipse...
> If somebody can help me I will be very very greatfull.
> Thanks in advance!
- - - - - - - - - -
  If the ellipse is oriented with the 'a' length semi-axis having an angle of 't' counterclockwise from the x-axis, the other semi-axis is length 'b', and the center of the ellipse is at (xc,yc), then

 ((x-xc)*cos(t)-(y-yc)*sin(t)).^2/a^2 + ...
 ((x-xc)*sin(t)+(y-yc)*cos(t)).^2/b^2 <= 1

is true if and only if (x,y) lies inside the ellipse.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us