From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Date: Thu, 29 Apr 2010 22:16:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <hrd0f4$4o1$>
References: <hrcrc2$3me$> <hrcs68$r8m$> <hrct9s$bpa$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1272579364 4865 (29 Apr 2010 22:16:04 GMT)
NNTP-Posting-Date: Thu, 29 Apr 2010 22:16:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:631133

"GAURAV " <> wrote in message <hrct9s$bpa$>...
> Hi Roger,
> Thanks for your reply..
> Actually its an assumption I am making.
> I have two curves(orthogonal to each other) aligned in 3D ( not necessarily symmetrical ).
> The height (along Z axis) is the same. So, when I cut a slice for some Z, I have four points (two from each curve).
> Now I need to construct a volume from these two views. So from each slice I am trying to fit in an ellipse. I hope this makes sense.
> So, now I have four points which pass through ellipse and ellipse should not go out of this bound .
> So, I am looking to solve the ellipse equation and try to find out of the a,b,xc and yc required for the ellipse with angle=0.
> Can you suggest something?
> Regards,
> Gaurav.

  For the four-point problem you can avoid using one of the non-linear methods by writing your equation in the following linear form.  Then use 'svd' to determine the five unknown coefficients:

 A*x^2 + C*y^2 + D*x + E*y + F = 0

Do this:

 x = [a1;a2;a3;a4];
 y = [b1;b2;b3;b4];
 M = [x.^2,y.^2,x,y,ones(4,1)];
 [U,S,V] = svd(M);
 A = V(1,5);
 C = V(2,5);
 D = V(3,5);
 E = V(4,5);
 F = V(5,5);

The fifth column of V has your desired coefficients.  These five coefficients should satisfy the above equation.

  By completion of the squares in the equation and dividing by the appropriate value you can then transform it into your original form and thereby determine a, b, xc, and xc.

  By way of explanation, this fifth column is the one corresponding to the zero-valued singular value of the matrix M, which causes it to be a solution to the equation.  There is bound to be at least one singular value because the number of rows in M is less that its number of columns, and 'svd' always puts the least singular value in the last column - the fifth in this case.

Roger Stafford