Date: Jan 19, 2013 2:14 PM
Author: Roger Stafford
Subject: Re: create polygon coordinates
"Jessica" wrote in message <email@example.com>...
> I have coordinates such as this:
> 384 360 60 69
> that represent the left, top, width, and height of an ellipse. How can I turn these values into a list that specifies a polygon?
> I would like to use this polygon list to find out whether particular X and Y coordinates fall inside this ellipse:
> k_inside1= inpolygon(X_Coordinate, Y_Coordinate, X_Polygon3, Y_Polygon3);
- - - - - - - - -
It seems a shame to approximate an ellipse with a polygon to see if points lie inside it, when a direct test with the simple equation of the ellipse would accomplish the same thing with much better accuracy and simplicity.
However, here are n vertices of a polygon approximating an ellipse. Let the ellipse be defined by the equation
(x-x0)^2/a^2 + (y-y0)^2/b^2 = 1
Then the vertices are given by:
t = linspace(0,2*pi,n); % <-- You choose n
x = a*cos(t)+x0;
y = b*sin(t)+y0;
Note: The spacing along the polygon is not uniform here. To do that would require the use of elliptic integrals.