转载务请说明出处:http://blog.csdn.net/CTeX/ 作者CTeX
function plotconic(f)
% 画椭圆 f是一般椭圆方程 : ax^2+bxy+cy^2+dx+ey+f=0.
% 之前先将其转化为椭圆的标准方程:
% (xcos(th)+ysin(th)-x_c cos(th)+y_c sin(th))^ 2/ A^2+(xsin(th)+ycos(th)-x_c sin(th)+y_ccos(th)) ^2/B^2=1
a = f(1);
b = f(2);
c = f(3);
d = f(4);
e = f(5);
f = f(6);
b^2 - 4*a*c
% first verify
if(b^2 >= 4*a*c)
disp('This is not a conic- Exiting');
return;
end
[cent_x,cent_y, sht_ax , lgn_ax ,theta] = ep_ord2stand(a,b,c,d,e,f) % 将一般椭圆方程转化为标准形式
ecc = axes2ecc(lgn_ax,sht_ax);
% [lat,lon] = ellipse1(cent_x+ x_center,cent_y+ y_center,[lgn_ax ecc],90-theta*180/pi);
[lat,lon] = ellipse1(cent_x,cent_y,[lgn_ax ecc],90-theta*180/pi); % 在椭圆采样得到坐标
plot(lat,lon)
function [cent_x,cent_y, sht_ax ,lgn_ax ,theta] = ep_ord2stand(a,b,c,d,e,f)
% 转化过程
% 参考文献:[1]Paul L Rosin Ellipse fitting by accumulating five-point fits -.Pattem Recognhian Letters,1993.14:661—669
% [2] 聂守平,椭圆型孔径几何参数测量 - 激光杂志, 2001
%[3] 刘书桂,李蓬,基于最小二乘原理的平面任意位置椭圆的评价,计量学报, 2002
% cent_x = (b*e-2*c*d)/(4*a*c - b*b);
% cent_y = (b*d-2*a*e)/(4*a*c - b*b);
% lgn_ax= -2*f/(a+c+f*sqrt(b*b+((a-c)/f).^2));
% lgn_ax = sqrt(abs(lgn_ax));
% sht_ax= -2*f/(a+c-f*sqrt(b*b+((a-c)/f).^2));
% sht_ax = sqrt(abs(sht_ax));
% theta = 0.5*atan(b/(a-c))
% if sht_ax > lgn_ax
% t = lgn_ax;
% lgn_ax = sht_ax;
% sht_ax = t;
% end
A = b/a;
B = c/a;
C = d/a;
D = e/a;
E = f/a;
cent_x = (2*B*C-A*D)/(A*A-4*B);
cent_y = (2*D-A*D)/(A*A-4*B);
lgn_ax= 2*(A*C*D - B*C*C - D*D + 4*B*E - A*A*E)/((A*A - 4*B)*(B - sqrt(A*A+(1-B)*(1-B))+1));
lgn_ax = sqrt(abs(lgn_ax));
sht_ax= 2*(A*C*D - B*C*C - D*D + 4*B*E - A*A*E)/((A*A - 4*B)*(B + sqrt(A*A+(1-B)*(1-B))+1));
sht_ax = sqrt(abs(sht_ax));
% theta = 0.5*atan((lgn_ax*lgn_ax - sht_ax*sht_ax*B)/(lgn_ax*lgn_ax*B - sht_ax*sht_ax))
theta = 0.5*atan(A/(1-B))
经实验证明,上述程序并不能画出任意椭圆,比如有倾斜角的椭圆。不知道是ellipse函数的问题还是椭圆参数求解有错,5点确定的椭圆一直不过