http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293
MATLAB Central Newsreader  Plot ellipse
Feed for thread: Plot ellipse
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 13 Jan 2009 15:57:02 +0000
Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621252
Glyn Hudson
Hi everyone,<br>
<br>
I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
<br>
Glyn.

Tue, 13 Jan 2009 17:27:01 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621295
Sadik
"Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkidke$9f9$1@fred.mathworks.com>...<br>
> Hi everyone,<br>
> <br>
> I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
> <br>
> Glyn. <br>
<br>
Hello Glyn,<br>
<br>
You know that the sum of the distances from a given point to the two foci should be the same on the ellipse. From here, you can get the equation of the ellipse. Then, you could find the minimum and the maximum x values. These correspond to the leftmost and the rightmost points of the ellipse on the plane. <br>
<br>
The general formula of an ellips:<br>
<br>
(xx0)^2/a^2+(yy0)^2/b^2=1<br>
<br>
Therefore, you can easily write x in terms of x0, y, y0, a and b. From here, you can easily identify the minimum and the maximum. <br>
<br>
Once you do that, let's say you found xmin and xmax to be the extrema, you can let x = xmin:deltaX:xmax;<br>
<br>
Now, we can write y in terms of x, just as we did for x and you get y as a function of x, x0, y0, a and b. If you take the positive squareroot term, you can plot the upper portion of the ellipse and the negative squareroot will yield the lower portion.<br>
<br>
Caution: You should chose deltaX quite small so that the points on the ellipse will not look inhomogenous [because they will be, in general].<br>
<br>
Hope this helps.

Tue, 13 Jan 2009 18:11:01 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621308
Sadik
"Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkidke$9f9$1@fred.mathworks.com>...<br>
> Hi everyone,<br>
> <br>
> I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
> <br>
> Glyn. <br>
<br>
I will make a correction [simplification, explanation, appendix] to my previous reply.<br>
<br>
You don't need to write x as a function of y to determine its range. Once you write y as a function of x and the other constants x0, y0, a and b, then you will see that<br>
<br>
y = y0 +/ b* sqrt(1(xx0)^2/a^2) ......................... (*)<br>
<br>
Since we don't want any complex value for y, we would require the term in the square root be nonnegative. For which range of x is it nonnegative?<br>
<br>
x0sqrt(a) <= x <= x0+sqrt(a) <br>
<br>
So you have your xmin = x0sqrt(a) and xmax x0 + sqrt(a) .<br>
<br>
The rest is the same as before. After you have your vector of values for x, you substitute it in (*) above, once for y0 + ... to get the vector yUpper, and once for y0  ... to get the vector yLower. Then, as you already know,<br>
<br>
plot(x,yUpper) <br>
hold on<br>
plot(x,yLower)<br>
<br>
Of course, all these describe the case when the major [or minor] axis is parallel to the xaxis. In the oblique case, however, you can follow the similar "we don't want complex" approach.<br>
<br>
Hope this helps.

Tue, 13 Jan 2009 18:23:01 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621312
Matt Fig
Have you looked on the file exchange?<br>
If that doesn't pan out, please refer to the picture at the top here:<br>
<br>
<a href="http://mathworld.wolfram.com/Ellipse.html">http://mathworld.wolfram.com/Ellipse.html</a><br>
<br>
and tell us what exactly you are given, i.e., both r1 and r2 or (r1 + r2) or what.

Tue, 13 Jan 2009 18:38:02 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621314
Matt Fig
And also, given focus coords [x1,x2] and [y1,y2], is it necessarily true that:<br>
<br>
(x1==x2  y1==y2)<br>
<br>
or can the ellipse be rotated? Also, what have you done so far?

Tue, 13 Jan 2009 22:59:02 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621362
Roger Stafford
"Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkidke$9f9$1@fred.mathworks.com>...<br>
> Hi everyone,<br>
> <br>
> I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
> <br>
> Glyn. <br>
<br>
Let the two foci have coordinates (x1,y1) and (x2,y2) and d be the given sum of the two distances from any point (x,y) on the ellipse to the two respective foci. Then do the following:<br>
<br>
c = 1/2*sqrt((x2x1)^2+(y2y1)^2);<br>
a = d/2;<br>
b = sqrt(a^2c^2);<br>
t = linspace(0,2*pi,1000);<br>
x = (x1+x2)/2 +(x2x1)/(2*c)*a*cos(t)  (y2y1)/(2*c)*b*sin(t);<br>
y = (y1+y2)/2 +(y2y1)/(2*c)*a*cos(t) +(x2x1)/(2*c)*b*sin(t);<br>
plot(x,y)<br>
axis equal<br>
<br>
This should give you the desired ellipse. As the parameter t varies from 0 to 2*pi the ellipse will be traced from a point on the opposite side of (x2,y2) from (x1,y1) around the ellipse in a counterclockwise direction until it returns to the start point. The quantities a and b are respectively the major and minor semiaxis lengths of the ellipse. Note that we must have d >= 2*c to have a valid ellipse.<br>
<br>
I'll let you figure out the reasoning behind all this. It just involves knowing a few facts about ellipses together with a translation and rotation of coordinates to put the ellipse in standard form.<br>
<br>
Roger Stafford

Wed, 14 Jan 2009 15:01:18 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621502
Glyn Hudson
"Matt Fig" <spamanon@yahoo.com> wrote in message <gkim65$jb9$1@fred.mathworks.com>...<br>
> Have you looked on the file exchange?<br>
> If that doesn't pan out, please refer to the picture at the top here:<br>
> <br>
> <a href="http://mathworld.wolfram.com/Ellipse.html">http://mathworld.wolfram.com/Ellipse.html</a><br>
> <br>
> and tell us what exactly you are given, i.e., both r1 and r2 or (r1 + r2) or what.<br>
<br>
Im given (r1 + r2)<br>
<br>
Its the total reflection distance between two transducers (the foci) and an object (the point on the ellispe)

Wed, 14 Jan 2009 15:05:04 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621503
Glyn Hudson
"Matt Fig" <spamanon@yahoo.com> wrote in message <gkin2a$ikg$1@fred.mathworks.com>...<br>
> And also, given focus coords [x1,x2] and [y1,y2], is it necessarily true that:<br>
> <br>
> (x1==x2  y1==y2)<br>
> <br>
> or can the ellipse be rotated? Also, what have you done so far?<br>
<br>
No it is not always true that (x1==x2  y1==y2) since the elipse will be rotated. i.e one of the ultrasound transducers (one of the foci) will be moved to simmulate an array of transducers. <br>
<br>
So far I have ploted an elipse given lenghths the major and minor axis and rotated the elipse about its center

Wed, 14 Jan 2009 15:47:01 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621515
Glyn Hudson
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gkj6bm$ms7$1@fred.mathworks.com>...<br>
> "Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkidke$9f9$1@fred.mathworks.com>...<br>
> > Hi everyone,<br>
> > <br>
> > I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
> > <br>
> > Glyn. <br>
> <br>
> Let the two foci have coordinates (x1,y1) and (x2,y2) and d be the given sum of the two distances from any point (x,y) on the ellipse to the two respective foci. Then do the following:<br>
> <br>
> c = 1/2*sqrt((x2x1)^2+(y2y1)^2);<br>
> a = d/2;<br>
> b = sqrt(a^2c^2);<br>
> t = linspace(0,2*pi,1000);<br>
> x = (x1+x2)/2 +(x2x1)/(2*c)*a*cos(t)  (y2y1)/(2*c)*b*sin(t);<br>
> y = (y1+y2)/2 +(y2y1)/(2*c)*a*cos(t) +(x2x1)/(2*c)*b*sin(t);<br>
> plot(x,y)<br>
> axis equal<br>
> <br>
> This should give you the desired ellipse. As the parameter t varies from 0 to 2*pi the ellipse will be traced from a point on the opposite side of (x2,y2) from (x1,y1) around the ellipse in a counterclockwise direction until it returns to the start point. The quantities a and b are respectively the major and minor semiaxis lengths of the ellipse. Note that we must have d >= 2*c to have a valid ellipse.<br>
> <br>
> I'll let you figure out the reasoning behind all this. It just involves knowing a few facts about ellipses together with a translation and rotation of coordinates to put the ellipse in standard form.<br>
> <br>
> Roger Stafford<br>
<br>
Thanks for your fantastic post, very helpfull.<br>
<br>
I have just plotted an elipse using your method, all looks good appart from the foci which seem to be in the wrong place. Here is a photo of the plot<br>
<br>
x1=2 y2=1<br>
x2=5 y2=5<br>
d=7<br>
<br>
<a href="http://picasaweb.google.co.uk/lh/photo/xLzLXylUvPHEokBINbt5g?feat=directlink">http://picasaweb.google.co.uk/lh/photo/xLzLXylUvPHEokBINbt5g?feat=directlink</a><br>
<br>
What do you think?

Wed, 14 Jan 2009 16:43:02 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621542
Roger Stafford
"Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkl1dl$mim$1@fred.mathworks.com>...<br>
> .......<br>
> I have just plotted an elipse using your method, all looks good appart from the foci which seem to be in the wrong place. Here is a photo of the plot<br>
> ......<br>
<br>
I looked at the ellipse in your website. As nearly as my poor eyes can make out, the unit tick marks along the xaxis are 25/32 of an inch apart on my screen while the units along the yaxis are only 18/32" apart. This kind of skewness can produce the effect you are seeing where the foci look out of place. I get the same phenomenon on my ellipse graphs unless I do the "axis equal" instruction. You should make sure your x and y units are scaled to be precisely equal.<br>
<br>
In any case, there is a far better way of directly testing your numerical results by adding the various sums of distances from the two given points and seeing if that sum remains essentially constant throughout the ellipse. Such a constancy can be true for only two points, namely the two true foci of the ellipse.<br>
<br>
I used<br>
<br>
max(abs(sqrt((xx1).^2+(yy1).^2)+sqrt((xx2).^2+(yy2).^2)d))<br>
<br>
as a test before sending the code to you and it was always very small, down around the 14th or 15th decimal place.<br>
<br>
Roger Stafford<br>

Wed, 14 Jan 2009 21:29:02 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#621667
Glyn Hudson
Yeah your totally right. Thanks a lot, much appreciated.<br>
<br>
Glyn. <br>
<br>
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gkl4mm$apq$1@fred.mathworks.com>...<br>
> "Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkl1dl$mim$1@fred.mathworks.com>...<br>
> > .......<br>
> > I have just plotted an elipse using your method, all looks good appart from the foci which seem to be in the wrong place. Here is a photo of the plot<br>
> > ......<br>
> <br>
> I looked at the ellipse in your website. As nearly as my poor eyes can make out, the unit tick marks along the xaxis are 25/32 of an inch apart on my screen while the units along the yaxis are only 18/32" apart. This kind of skewness can produce the effect you are seeing where the foci look out of place. I get the same phenomenon on my ellipse graphs unless I do the "axis equal" instruction. You should make sure your x and y units are scaled to be precisely equal.<br>
> <br>
> In any case, there is a far better way of directly testing your numerical results by adding the various sums of distances from the two given points and seeing if that sum remains essentially constant throughout the ellipse. Such a constancy can be true for only two points, namely the two true foci of the ellipse.<br>
> <br>
> I used<br>
> <br>
> max(abs(sqrt((xx1).^2+(yy1).^2)+sqrt((xx2).^2+(yy2).^2)d))<br>
> <br>
> as a test before sending the code to you and it was always very small, down around the 14th or 15th decimal place.<br>
> <br>
> Roger Stafford<br>
>

Wed, 27 Jul 2011 09:33:10 +0000
Re: Plot ellipse
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242293#846906
Mahdiye
"Glyn Hudson" <g.d.hudson@warwick.ac.uk> wrote in message <gkidke$9f9$1@fred.mathworks.com>...<br>
> Hi everyone,<br>
> <br>
> I'm trying to plot an ellipse in 2D given coordinates of the two foci and the distance between a point on the ellipse and the foci. What do you think is the best way to approach this? <br>
> <br>
> Glyn. <br>
hi dear<br>
you can use the "pdeellip" for plot in 2dellipse.<br>
good luck