平面椭圆参数方程推导
ax2+bxy+cy2+dx+ey+f=0ax^2+bxy+cy^2+dx+ey+f=0ax2+bxy+cy2+dx+ey+f=0
可以看作一个由一个Ax2+By2+C=0Ax^2+By^2+C=0Ax2+By2+C=0的椭圆逆时针旋转θ\thetaθ再向右平移x0x_0x0,向上平移y0y_0y0得到
其中,不妨令0<A<B,θ∈[−π2,π2]0<A<B,\theta\in[-\frac{\pi}{2},\frac{\pi}{2}]0<A<B,θ∈[−2π,2π],显然C<0C<0C<0
逆时针旋转θ\thetaθ后,方程变为
A(xcos(θ)+ysin(θ))2+B(−xsin(θ)+ycos(θ))2+C=0
A(x\cos(\theta)+y\sin(\theta))^2+B(-x\sin(\theta)+y\cos(\theta))^2+C =0
A(xcos(θ)+ysin(θ))2+B(−xsin(θ)+ycos(θ))2+C=0
%验证
A=1;B=4;C=-4;
thetas = deg2rad([-90,-60,-30,30,60,90]);
for ii = 1:1:length(thetas);
subplot(1,length(thetas),ii)
theta = thetas(ii);
c = cos(theta);
s = sin(theta);
fa = [num2str(A),'*','(x*',num2str(c),'+y*',num2str(s),')^2'];
fb = [num2str(B),'*','(-x*',num2str(s),'+y*',num2str(c),')^2'];
f = [fa,'+',fb,'+',num2str(C)];
ezplot(f);
axis equal
end
展开后
A(xcos(θ)+ysin(θ))2+B(−xsin(θ)+ycos(θ))2+C=0
A(x\cos(\theta)+y\sin(\theta))^2+B(-x\sin(\theta)+y\cos(\theta))^2+C =0
A(xcos(θ)+ysin(θ))2+B(−xsin(θ)+ycos(θ))2+C=0
也即
x2(Acos2θ+Bsin2θ)+xy((A−B)sin(2θ))+y2(Asin2θ+Bcos2θ)+C=0
x^2(A\cos^2\theta+B\sin^2\theta)+xy((A-B)\sin(2\theta))+y^2(A\sin^2\theta+B\cos^2\theta)+C = 0
x2(Acos2θ+Bsin2θ)+xy((A−B)sin(2θ))+y2(Asin2θ+Bcos2θ)+C=0
向右平移x0x_0x0,向上平移y0y_0y0后
(x−x0)2(Acos2θ+Bsin2θ)+(x−x0)(y−y0)((A−B)sin(2θ))+(y−y0)2(Asin2θ+Bcos2θ)+C=0 (x-x_0)^2(A\cos^2\theta+B\sin^2\theta)+ (x-x_0)(y-y_0)((A-B)\sin(2\theta))\\+(y-y_0)^2(A\sin^2\theta+B\cos^2\theta)+C = 0 (x−x0)2(Acos2θ+Bsin2θ)+(x−x0)(y−y0)((A−B)sin(2θ))+(y−y0)2(Asin2θ+Bcos2θ)+C=0
(x−x0)2(Acos2θ+Bsin2θ)=x2(Acos2θ+Bsin2θ)−x(2x0(Acos2θ+Bsin2θ))+x02(Acos2θ+Bsin2θ) (x-x_0)^2(A\cos^2\theta+B\sin^2\theta) \\=x^2(A\cos^2\theta+B\sin^2\theta)\\-x(2x_0(A\cos^2\theta+B\sin^2\theta))\\+{x_0}^2(A\cos^2\theta+B\sin^2\theta) (x−x0)2(Acos2θ+Bsin2θ)=x2(Acos2θ+Bsin2θ)−x(2x0(Acos2θ+Bsin2θ))+x02(Acos2θ+Bsin2θ)
(x−x0)(y−y0)((A−B)sin(2θ))=xy((A−B)sin(2θ))−x(y0(A−B)sin(2θ))−y(x0(A−B)sin(2θ))+x0y0((A−B)sin(2θ)) (x-x_0)(y-y_0)((A-B)\sin(2\theta))\\ =xy((A-B)\sin(2\theta))\\ -x(y_0(A-B)\sin(2\theta))\\ -y(x_0(A-B)\sin(2\theta))\\ +x_0y_0((A-B)\sin(2\theta)) (x−x0)(y−y0)((A−B)sin(2θ))=xy((A−B)sin(2θ))−x(y0(A−B)sin(2θ))−y(x0(A−B)sin(2θ))+x0y0((A−B)sin(2θ))
(y−y0)2(Asin2θ+Bcos2θ)=y2(Asin2θ+Bcos2θ)−y(2y0(Asin2θ+Bcos2θ))+y02(Asin2θ+Bcos2θ) (y-y_0)^2(A\sin^2\theta+B\cos^2\theta) \\=y^2(A\sin^2\theta+B\cos^2\theta)\\-y(2y_0(A\sin^2\theta+B\cos^2\theta))\\+{y_0}^2(A\sin^2\theta+B\cos^2\theta) (y−y0)2(Asin2θ+Bcos2θ)=y2(Asin2θ+Bcos2θ)−y(2y0(Asin2θ+Bcos2θ))+y02(Asin2θ+Bcos2θ)
已知量a,b,c,d,e,fa,b,c,d,e,fa,b,c,d,e,f与未知量A,B,θ,x0,y0,CA,B,\theta,x_0,y_0,CA,B,θ,x0,y0,C的关系
a=Acos2θ+Bsin2θb=(A−B)sin(2θ)c=Asin2θ+Bcos2θd=−2ax0−by0e=−bx0−2cy0f=ax02+bx0y0+cy02+C
a = A\cos^2\theta+B\sin^2\theta\\
b = (A-B)\sin(2\theta)\\
c = A\sin^2\theta+B\cos^2\theta\\
d = -2ax_0-by_0\\
e = -bx_0-2cy_0\\
f = a{x_0}^2+b{x_0}{y_0}+c{y_0}^2+C
a=Acos2θ+Bsin2θb=(A−B)sin(2θ)c=Asin2θ+Bcos2θd=−2ax0−by0e=−bx0−2cy0f=ax02+bx0y0+cy02+C
求解A,B,θA,B,\thetaA,B,θ
a+c=A+Ba−c=(A−B)cos(2θ)b=(A−B)sin(2θ)
a+c = A+B\\
a-c = (A-B)\cos(2\theta)\\
b = (A-B)\sin(2\theta)\\
a+c=A+Ba−c=(A−B)cos(2θ)b=(A−B)sin(2θ)
A<B,θ∈[−π2,π2]A<B,\theta\in[-\frac{\pi}{2},\frac{\pi}{2}]A<B,θ∈[−2π,2π],所以
(a−c)2+b2=B−AA=a+c−(a−c)2+b22B=a+c+(a−c)2+b22
\sqrt{(a-c)^2+b^2} = B-A\\
A = \frac{a+c - \sqrt{(a-c)^2+b^2}}{2}\\
B = \frac{a+c + \sqrt{(a-c)^2+b^2}}{2}\\
(a−c)2+b2=B−AA=2a+c−(a−c)2+b2B=2a+c+(a−c)2+b2
if(a-c<0)
theta = 1/2*asin(b/(A-B));
elseif(b<0)
theta = pi/2 - 1/2*asin(b/(A-B));
else
theta = -pi/2 - 1/2*asin(b/(A-B));
end
求解x0,y0
x0=(2cd−be)/(b2−4ac)y0=(2ae−bd)/(b2−4ac)
x_0 = (2cd-be)/(b^2 - 4ac)\\
y_0 = (2ae-bd)/(b^2 - 4ac)
x0=(2cd−be)/(b2−4ac)y0=(2ae−bd)/(b2−4ac)
求解CCC
C=f−ax02−bx0y0−cy02
C = f - a{x_0}^2-b{x_0}{y_0}-c{y_0}^2
C=f−ax02−bx0y0−cy02
(x−x0)2(Acos2θ+Bsin2θ)+(x−x0)(y−y0)((A−B)sin(2θ))+(y−y0)2(Asin2θ+Bcos2θ)+C=0 (x-x_0)^2(A\cos^2\theta+B\sin^2\theta)+ (x-x_0)(y-y_0)((A-B)\sin(2\theta))\\+(y-y_0)^2(A\sin^2\theta+B\cos^2\theta)+C = 0 (x−x0)2(Acos2θ+Bsin2θ)+(x−x0)(y−y0)((A−B)sin(2θ))+(y−y0)2(Asin2θ+Bcos2θ)+C=0
令x1=x−x0,y1=y−y0x_1 = x-x_0,y_1=y-y_0x1=x−x0,y1=y−y0,也即x=x1+x0,y=y0+y1x = x_1+x_0,y= y_0 + y_1x=x1+x0,y=y0+y1
x12(Acos2θ+Bsin2θ)+x1y1((A−B)sin(2θ))+y12(Asin2θ+Bcos2θ)+C=0
x_1^2(A\cos^2\theta+B\sin^2\theta)+x_1y_1((A-B)\sin(2\theta))+y_1^2(A\sin^2\theta+B\cos^2\theta)+C = 0
x12(Acos2θ+Bsin2θ)+x1y1((A−B)sin(2θ))+y12(Asin2θ+Bcos2θ)+C=0
[x1y1][Acos2θ+Bsin2θ(A−B)sin(θ)cos(θ)(A−B)sin(θ)cos(θ)Asin2θ+Bcos2θ][x1y1]+C=0 \begin{bmatrix} x_1&y_1 \end{bmatrix} \begin{bmatrix} A\cos^2\theta+B\sin^2\theta&(A-B)\sin(\theta)\cos(\theta)\\ (A-B)\sin(\theta)\cos(\theta)&A\sin^2\theta+B\cos^2\theta\\ \end{bmatrix} \begin{bmatrix} x_1\\y_1 \end{bmatrix}+C = 0 [x1y1][Acos2θ+Bsin2θ(A−B)sin(θ)cos(θ)(A−B)sin(θ)cos(θ)Asin2θ+Bcos2θ][x1y1]+C=0
([cos(θ)sin(θ)−sin(θ)cos(θ)][x1y1])T[A00B][cos(θ)sin(θ)−sin(θ)cos(θ)][x1y1]+C=0 (\begin{bmatrix} \cos(\theta)&\sin(\theta)\\ -\sin(\theta)&\cos(\theta)\\ \end{bmatrix} \begin{bmatrix} x_1\\y_1 \end{bmatrix})^\mathrm{T} \begin{bmatrix} A&0\\0&B \end{bmatrix}\begin{bmatrix} \cos(\theta)&\sin(\theta)\\ -\sin(\theta)&\cos(\theta)\\ \end{bmatrix}\begin{bmatrix} x_1\\y_1 \end{bmatrix}+C = 0 ([cos(θ)−sin(θ)sin(θ)cos(θ)][x1y1])T[A00B][cos(θ)−sin(θ)sin(θ)cos(θ)][x1y1]+C=0
令x2=x1cos(θ)+y1sin(θ),y2=−x1sin(θ)+y1cos(θ)x_2 = x_1\cos(\theta)+y_1\sin(\theta),y_2 = -x_1\sin(\theta)+y_1\cos(\theta)x2=x1cos(θ)+y1sin(θ),y2=−x1sin(θ)+y1cos(θ),也即x1=x2cos(θ)−y2sin(θ),y1=x2sin(θ)+y2cos(θ)x_1 = x_2\cos(\theta)-y_2\sin(\theta),y_1 = x_2\sin(\theta)+y_2\cos(\theta)x1=x2cos(θ)−y2sin(θ),y1=x2sin(θ)+y2cos(θ)
Ax22+By22+C=0
Ax_2^2 + By_2^2+C = 0
Ax22+By22+C=0
参数方程
x2=−CAcos(t)y2=−CBsin(t)
x_2 = \sqrt{\frac{-C}{A}}\cos(t)\\
y_2 = \sqrt{\frac{-C}{B}}\sin(t)
x2=A−Ccos(t)y2=B−Csin(t)
x1=−CAcos(θ)cos(t)−−CBsin(θ)sin(t)y1=−CAsin(θ)cos(t)+−CBcos(θ)sin(t) x_1 = \sqrt{\frac{-C}{A}}\cos(\theta)\cos(t)-\sqrt{\frac{-C}{B}}\sin(\theta)\sin(t)\\ y_1 = \sqrt{\frac{-C}{A}}\sin(\theta)\cos(t)+\sqrt{\frac{-C}{B}}\cos(\theta)\sin(t) x1=A−Ccos(θ)cos(t)−B−Csin(θ)sin(t)y1=A−Csin(θ)cos(t)+B−Ccos(θ)sin(t)
最终参数方程
x=−CAcos(θ)cos(t)−−CBsin(θ)sin(t)+x0y=−CAsin(θ)cos(t)+−CBcos(θ)sin(t)+y0
x= \sqrt{\frac{-C}{A}}\cos(\theta)\cos(t)-\sqrt{\frac{-C}{B}}\sin(\theta)\sin(t)+x_0\\
y= \sqrt{\frac{-C}{A}}\sin(\theta)\cos(t)+\sqrt{\frac{-C}{B}}\cos(\theta)\sin(t)+y_0
x=A−Ccos(θ)cos(t)−B−Csin(θ)sin(t)+x0y=A−Csin(θ)cos(t)+B−Ccos(θ)sin(t)+y0
已知量 | 未知量 | 表达式 |
---|---|---|
a | A | a+c−(a−c)2+b22\frac{a+c - \sqrt{(a-c)^2+b^2}}{2}2a+c−(a−c)2+b2 |
b | B | a+c+(a−c)2+b22\frac{a+c + \sqrt{(a-c)^2+b^2}}{2}2a+c+(a−c)2+b2 |
c | C | f−ax02−bx0y0−cy02f - a{x_0}^2-b{x_0}{y_0}-c{y_0}^2f−ax02−bx0y0−cy02 |
d | x0x_0x0 | (2cd−be)/(b2−4ac)(2cd-be)/(b^2 - 4ac)(2cd−be)/(b2−4ac) |
e | y0y_0y0 | (2ae−bd)/(b2−4ac)(2ae-bd)/(b^2 - 4ac)(2ae−bd)/(b2−4ac) |
f | θ\thetaθ | 见上述matlab代码见上述matlab代码见上述matlab代码 |
验证代码
clf;
a = rand(1);
b = rand(1);
c = rand(1);
d = 0.5*rand(1)-0.25;
e = 0.5*rand(1)-0.25;
f = 100*rand(1)-100;
func = @(x,y)(a*x*x+b*x*y+c*y*y+d*x+e*y+f);
fimplicit(func);
axis([-50,50,-50,50]);
pause(1);
aa = (a+c - sqrt((a-c)^2+b^2))/2;
bb = (a+c + sqrt((a-c)^2+b^2))/2;
x0 = (2*c*d-b*e)/(b*b-4*a*c);
y0 = (2*a*e-b*d)/(b*b-4*a*c);
cc = f-a*x0*x0-b*x0*y0-c*y0*y0;
if(a-c<0)
theta = 1/2*asin(b/(aa-bb));
elseif(b<0)
theta = pi/2 - 1/2*asin(b/(aa-bb));
else
theta = -pi/2 - 1/2*asin(b/(aa-bb));
end
xt = @(t)(sqrt(-cc/aa)*cos(theta)*cos(t)-sqrt(-cc/bb)*sin(theta)*sin(t)+x0);
yt = @(t)(sqrt(-cc/aa)*sin(theta)*cos(t)+sqrt(-cc/bb)*cos(theta)*sin(t)+y0);
tt = linspace(0,2*pi,100);
xplot = zeros(1,100);
yplot = zeros(1,100);
for ii = 1:1:100
xplot(ii) = xt(tt(ii));
yplot(ii) = yt(tt(ii));
end
hold on;plot(xplot,yplot);