【编程实践】使用matlab求椭圆弧长

1 椭圆的表达式

Standard equation:
x 2 a 2 + y 2 b 2 = 1 \frac{x^2}{a^2}+\frac{y^2} {b^2}=1 a2x2+b2y2=1
Parametric equation:
x = a c o s α y = b s i n α \begin{align*} x=acos\alpha \\y=bsin\alpha \end{align*} x=acosαy=bsinα
General form equation:
A x 2 + B x y + C y 2 + D x + E y + F = 0 Ax^2+Bxy+Cy^2+Dx+Ey+F=0 Ax2+Bxy+Cy2+Dx+Ey+F=0
thereinto

A = a 2 s i n 2 θ + b 2 c o s 2 θ B = 2 ( b 2 − a 2 ) s i n θ c o s θ C = a 2 c o s 2 θ + b 2 s i n 2 θ D = − 2 A x 0 − B y 0 E = − B x 0 − 2 C y 0 F = − 1 2 ( D x 0 + E y 0 ) − a 2 b 2 \begin{align*} A = a^2sin^2\theta+b^2cos^2\theta \\B=2(b^2-a^2) sin\theta cos\theta \\C=a^2cos^2\theta +b^2sin^2\theta \\D=-2Ax_0-By_0 \\E=-Bx_0-2Cy_0 \\F=-\frac{1}{2}(Dx_0+Ey_0)-a^2b^2 \end{align*} A=a2sin2θ+b2cos2θB=2(b2a2)sinθcosθC=a2cos2θ+b2sin2θD=2Ax0By0E=Bx02Cy0F=21(Dx0+Ey0)a2b2
x 0 , y 0 x_0,y_0 x0,y0为椭圆圆心坐标, a , b a,b a,b分别为椭圆的长短半轴, θ \theta θ为长半轴与x轴的夹角。

2 椭圆的弧长计算理论公式

l = a ∫ θ 1 θ 2 1 − e 2 s i n 2 θ , θ 1 , θ 2 ∈ [ 0 , π 2 ] l=a\int_{\theta_1}^{\theta_2}\sqrt{1-e^2sin^2\theta} ,\theta_1,\theta_2\in[0,\frac{\pi}{2}] l=aθ1θ21e2sin2θ θ1,θ2[0,2π]
thereinto, e = 1 − b 2 a 2 e=\sqrt{1-\frac{b^2}{a^2}} e=1a2b2 . Here, the angle we talk about is in the first quadrant.

C = 4 l C=4l C=4l
Using the Taylor series expansion, the circumference of the ellipse is
C ≈ π ( a + b ) C\approx\pi(a+b) Cπ(a+b)

3 以具体案例计算

x 2 3 2 + y 2 2 2 = 1 \frac{x^2}{3^2}+\frac{y^2}{2^2}=1 32x2+22y2=1

// 参数方程
theta = 0:0.01:2*pi %起止角度和步长
X = 3*cos(theta)
Y = 2*sin(theta)
plot(X,Y)

绘图输出显示🦢:
在这里插入图片描述

// 标准形式
theta = 0:0.01:2*pi
f =@(X,Y)X.^2/9+Y.^2/4-1
plot(X,Y)

绘图输出显示🦏:
在这里插入图片描述

// An highlighted block

% 参数设定
a = 3
b = 2
e = sqrt(1-b^2/a^2)

theta_1 = 0 %起始角度
theta_2 = pi/2 %终止角度
theta_x = theta_1:0.01:theta_2 % 被积区间


y= a * sqrt(1-e.^2*sin(theta_x).^2) % 直接以被积函数声明
syms theta_vx
y2=@(theta_vx)a * sqrt(1-e.^2*sin(theta_vx).^2) % 匿名函数,被积函数句柄


trapz(theta_x,y) % 梯度积分,trapz(X,Y)根据X指定的坐标或标量间距对Y进行积分,因椭圆第一象限曲线为凸曲线,则梯度法计算结果略小于精确值
quadgk(y2,theta_1,theta_2) % 高斯-勒让德积分,使用高阶全局自适应积分和默认误差容限在区间内对函数句柄求积分
integral(y2,theta_1,theta_2) % 数值积分,使用全局自适应积分和模型误差容限在区间内以数值形式为函数求积分

运行结果🐳:
在这里插入图片描述
另, [ 0 , π 2 ] [0, \frac{\pi}{2}] [0,2π]区间四分之一椭圆弧长不精确计算结果:
a n s = π ∗ ( a + b ) / 4 = 3.1415 ∗ ( 2 + 3 ) / 4 = 3.9268 ans=\pi*(a+b)/4=3.1415*(2+3)/4=3.9268 ans=π(a+b)/4=3.1415(2+3)/4=3.9268

相同角度范围,椭圆弧长结果对比:
----------🌴---------- [ π 4 , π 2 ] [\frac{\pi}{4},\frac{\pi}{2}] [4π,2π]间距下,

----------🌴---------- [ 0 , π 4 ] [0,\frac{\pi}{4}] [0,4π]间距下,
在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值