橢圓的一般式為:\[A{x^2} + Bxy + C{y^2} + Dx + Ey + F = 0\]
橢圓的參數為:長半軸 $a$ 短半軸 $b$ 橢圓中心 $(x_{0},y_{0})$ 傾角為 $\theta$ (定義逆時針為正,長軸與x正方向的夾角)
1.由橢圓參數轉化為一般式:
推導過程:
橢圓 $C[3*3]$ ,中心在原點,長軸與x軸重合,經過旋轉矩陣 ${R} =f({\theta})$ , 平移矩陣 ${T}$$ =$$g$$(x_{0},y_{0})$ ,
后得到
$C^{'}=T^{T}*R^{T}*C*R*T$
ps:關於旋轉矩陣R和平移矩陣T的定義看上篇博文 直角坐標系下點/曲線平移與旋轉的矩陣計算
即 $H({\theta},x_{0},y_{0},a,b)=A{x^2} + Bxy + C{y^2} + Dx + Ey + F $
對應相等可以得到:
① $A = \frac{{{{\cos }^2}\theta }}{{{a^2}}} + \frac{{{{\sin }^2}\theta }}{{{b^2}}}$
② $B = 2 \cdot \sin \theta \cdot \cos \theta \cdot (\frac{1}{{{a^2}}} - \frac{1}{{{b^2}}})$
③ $C = \frac{{{{\cos }^2}\theta }}{{{b^2}}} + \frac{{{{\sin }^2}\theta }}{{{a^2}}}$
④ $D = - 2 \cdot [{x_0} \cdot (\frac{{{{\cos }^2}\theta }}{{{a^2}}} + \frac{{{{\sin }^2}\theta }}{{{b^2}}}) + {y_0} \cdot \sin \theta \cdot \cos \theta \cdot (\frac{1}{{{a^2}}} - \frac{1}{{{b^2}}})]$
⑤ $E = - 2 \cdot [{x_0} \cdot \sin \theta \cdot \cos \theta \cdot (\frac{1}{{{a^2}}} - \frac{1}{{{b^2}}}) + {y_0} \cdot (\frac{{{{\cos }^2}\theta }}{{{b^2}}} + \frac{{{{\sin }^2}\theta }}{{{a^2}}})]$
⑥ $F = \frac{{{{({x_0} \cdot \cos \theta + {y_0} \cdot \sin \theta )}^2}}}{{{a^2}}} + \frac{{{{({x_0} \cdot \sin \theta - {y_0} \cdot \cos \theta )}^2}}}{{{b^2}}} - 1$
matlab推導過程
+驗證
clc syms a b theta x0 y0 % 公式推導 C = [1/a.^2 0 0; 0 1/b.^2 0; 0 0 -1;]; Rot = [cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1;]; T = [1 0 -x0; 0 1 -y0; 0 0 1;]; C1 = T'*Rot'*C*Rot*T; %公式驗證 as = a*a; bs = b*b; coss = cos(theta).^2; sins = sin(theta).^2; cs = sin(theta)*cos(theta); A =coss/as+sins/bs; B =2*cs*(1/as-1/bs); C = coss/bs +sins/as; D = -(2*A*x0 +B*y0); E = -(B*x0 +2*A*y0); F = (x0*cos(theta)+y0*sin(theta)).^2/as+(x0*sin(theta)-y0*cos(theta)).^2/bs-1 a = 3; b = 2; x0 = 1; y0 = 0.5; theta = 0.1; A = eval(A) B = eval(B) C = eval(C) D = eval(D) E = eval(E) F = eval(F) syms x y f1 = ezplot( A*x^2+ C*y^2 +F + B*x*y + D*x +E*y,[-2,6],[-2,6]); set(f1,'Color','r','LineWidth',1.5) xlim([-2,6]) ylim([-2,6]) axis equal grid on
2.由一般式得到橢圓參數式:
橢圓的一般式為:\[A{x^2} + Bxy + C{y^2} + Dx + Ey + F = 0\]
由①②③式可以得到:
長半軸: $a^{2}=\frac{2}{A+C-\sqrt{B^{2}+(A-C)^{2}}}$
短半軸: $b^{2}=\frac{2}{A+C+\sqrt{B^{2}+(A-C)^{2}}}$
傾角: ${\theta} = arcsin({ sign(-B) \sqrt{\frac{(Aa^{2}-Cb^{2})a^{2}b^{2}}{a^{4}-b^{4}}}})$
偏移:alpha = cos(theta).^2/a^2+sin(theta).^2/b^2;
beta = sin(theta)*cos(theta)*(1/a^2-1/b^2);
gama = cos(theta).^2/b^2+sin(theta).^2/a^2;
y0 = (E/2 - beta*D/(2*alpha))/(beta^2/alpha - gama)
x0 = (-D/2 - beta*y0)/alpha
%接上面程序運行 aa = 2/(A+C-sqrt(B^2+(A-C).^2)) bb = 2/(A+C+sqrt(B^2+(A-C).^2)) if(bb > aa) temp = aa; aa = bb; bb = temp; end theta theta2 = asin(sign(-B)*sqrt((A*aa-C*bb)*aa*bb/(aa*aa-bb*bb))) a = sqrt(aa) b = sqrt(bb) alpha = cos(theta).^2/a^2+sin(theta).^2/b^2; beta = sin(theta)*cos(theta)*(1/a^2-1/b^2); gama = cos(theta).^2/b^2+sin(theta).^2/a^2; y0 = (E/2 - beta*D/(2*alpha))/(beta^2/alpha - gama) x0 = (-D/2 - beta*y0)/alpha