Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to find pixels inside ellipse ?
Date: Wed, 17 Aug 2011 16:04:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 35
Message-ID: <j2gopq$78p$1@newscl01ah.mathworks.com>
References: <g1bsct$ggh$1@fred.mathworks.com> <g1c6l2$b04$1@fred.mathworks.com> <j2ellm$gt5$1@newscl01ah.mathworks.com> <j2eomo$q1e$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1313597050 7449 172.30.248.35 (17 Aug 2011 16:04:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 17 Aug 2011 16:04:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2486811
Xref: news.mathworks.com comp.soft-sys.matlab:740304

"Roger Stafford" wrote in message <j2eomo$q1e$1@newscl01ah.mathworks.com>...
> "Cody Oppermann" wrote in message <j2ellm$gt5$1@newscl01ah.mathworks.com>...
> > "Roger Stafford" wrote in message <g1c6l2$b04$1@fred.mathworks.com>...
> > >   I assume you also know the location of the ellipse's center.  Call that (x0,y0).  
> > > Let t be the counterclockwise angle the major axis makes with respect to the 
> > > x-axis.  Let a and b be the semi-major and semi-minor axes, respectively.  If 
> > > P = (x,y) is an arbitrary point then do this:
> > > 
> > >  X = (x-x0)*cos(t)+(y-y0)*sin(t); % Translate and rotate coords.
> > >  Y = -(x-x0)*sin(t)+(y-y0)*cos(t); % to align with ellipse
> > > 
> > > If
> > > 
> > >  X^2/a^2+Y^2/b^2
> > > 
> > > is less than 1, the point P lies inside the ellipse.  If it equals 1, it is right on 
> > > the ellipse.  If it is greater than 1, P is outside.
> > > 
> > > Roger Stafford
> > 
> > I was curious how to do this with lat lon points. I have data describing a rotated ellipse (the center of the ellipse in lat lon coordinates, the lengths of the major and minor axes in kilometers, and the angle that the ellipse is oriented). I do not know the location of the foci, but assume there is a way to figure them out somehow. How can I determine if a specific lat lon point is within this ellipse?
> > 
> > Thanks,
> > Cody
> - - - - - - - - - -
>   It depends on the size of the ellipse and your accuracy requirements.  The easy way is to approximate the region in the vicinity of the ellipse with a flat plane (as in a map quadrangle) and convert longitude/latitude values of all points to be tested over to east/west and north/south kilometer coordinates relative to the position of the ellipse's center.  At the center's latitude, longitude differences correspond approximately to a number of kilometers in the east/west direction as determined by the cosine of the latitude.  Latitude differences always correspond to a fixed difference in north/south kilometers (assuming a spherical earth.)  Then solve the problem as given earlier in this thread.
> 
>   On the other hand if the above is not sufficiently accurate, you are faced with a problem in spherical geometry.  To begin with you need to define what an "ellipse" is to be on an (approximately) spherical earth.  It can no longer be a planar curve - all planar intersections with a sphere are circles.  I won't proceed any further along this line at the moment, assuming hopefully that the procedure in the first paragraph is sufficiently accurate for your purposes.
> 
> Roger Stafford

Thanks Roger, I was planning on using the flat plane assumption as my ellipses are relatively small. Just to clarify though, say I have a point, for example, at 30°,-30° and the center of my ellipse is at, say, 29°,-29°. Would it be most accurate if x-x0 is the distance from 29°,-29° to 29°,-30° (as opposed to 30°,-30° to 30°,-29°) and y-y0 is the distance from 29°,-29° to 30°,-29° (as opposed to 30°,-30° to 29°,-30°)?
Thanks again.
30,-30 •     • 30,-29
29,-30 •     • 29,-29