主程序:
clear%1 已知参数
alpha_0=0phi_0=0
theta_1=[4590135]*pi/180
theta_3=[5282112]*pi/180
d=50
%2 计算各杆长度
[l,m,n]=link_design(theta_1,theta_3,alpha_0,phi_0)
b=l*d/n
c=d*m/n
a=d/n
%3 输出计算结果
disp('计算结果1:各干相对长度')
disp(' ')
fprintf('连杆相对长度 l=%3.2f \n',l)
fprintf('摇杆相对长度 m=%3.2f \n',m)
fprintf('机架相对长度 n=%3.2f \n',n)
disp(' ')
disp('计算结果2:各干长度')
disp(' ')
fprintf('曲柄长度 a=%3.2f \n',a)
fprintf('连杆长度 b=%3.2f \n',b)
fprintf('摇杆长度 c=%3.2f \n',c)
fprintf('机架长度 d=%3.2f \n',d)
disp(' ')
子程序(link_design,m)
function [l,m,n]=link_design(theta_1,theta_3,alpha_0,phi_0)%计算线性方程组系数矩阵A
A=[cos(theta_3(1)+phi_0),cos(theta_3(1)+phi_0-theta_1(1)-alpha_0),1
cos(theta_3(2)+phi_0),cos(theta_3(2)+phi_0-theta_1(2)-alpha_0),1
cos(theta_3(3)+phi_0),cos(theta_3(3)+phi_0-theta_1(3)-alpha_0),1]
% 计算线性方程组系数矩阵B
B=[cos(theta_1(1)+alpha_0)cos(theta_1(2)+alpha_0)cos(theta_1(3)+alpha_0)]
% 求解线性方程组
p=A\B
% 计算相对杆长l,m,n
p0=p(1)p1=p(2)p2=p(3)
m=p0
n=-m/p1
l=sqrt(m*m+n*n+1-p2*2*n)
结果
计算结果1:各干相对长度
连杆相对长度 l=2.07
摇杆相对长度 m=1.49
机架相对长度 n=1.81
计算结果2:各干长度
曲柄长度 a=27.63
连杆长度 b=57.24
摇杆长度 c=41.11
机架长度 d=50.00
'新建窗体,添加command1,label1,hscroll1,timer1,picture1const
pi
=
3.1415926
dim
angle
as
integer
private
sub
form_load()
'调整空间尺寸,位置及初始参数
me.scalemode
=
3
me.caption
=
"曲柄滑块机构的演示"
me.width
=
5000
me.height
=
3500
picture1.scalemode
=
3
picture1.autoredraw
=
true
picture1.move
0,
0,
me.scalewidth,
150
command1.caption
=
"开始(&b)"
command1.move
20,
160,
70,
30
label1.caption
=
"速度:"
label1.move
120,
170,
100,
30
hscroll1.min
=
1
hscroll1.max
=
20
hscroll1.move
160,
160,
140,
30
timer1.interval
=
20
timer1.enabled
=
false
end
sub
private
sub
command1_click()
timer1.enabled
=
not
timer1.enabled
if
timer1.enabled
then
command1.caption
=
"暂停(&s)"
else
command1.caption
=
"开始(&b)"
end
if
end
sub
sub
draw(byval
ox
as
integer,
byval
oy
as
integer,
byval
orad
as
integer)
'ox,oy圆心坐标,orad半径
angle
=
(angle
+
hscroll1.value)
mod
360
xo
=
ox
+
orad
*
cos(angle
*
pi
/
180)
'圆周上的铰链点坐标(xo,yo)
yo
=
oy
+
orad
*
sin(angle
*
pi
/
180)
xs
=
sqr((4
*
orad)
^
2
-
10
^
2)
+
xo
'滑块的左边界x坐标,连杆长度取4*orad,滑块高度取20(像素)
picture1.backcolor
=
picture1.backcolor
picture1.drawstyle
=
0
'实线
picture1.drawwidth
=
2
'线宽2
picture1.line
(ox
+
2
*
orad,
oy)-(ox
+
6
*
orad,
oy)
'壁面
picture1.line
(ox,
oy)-(xo,
yo)
'连接圆心与圆周上的铰链点
picture1.line
(xs,
oy
-
10)-(xo,
yo),
vbblue
'连接滑块与圆周上的铰链点
picture1.fillstyle
=
1
'透明填充
picture1.circle
(ox,
oy),
orad
'画圆
picture1.fillstyle
=
0
'实体填充
picture1.fillcolor
=
vbwhite
'圆心
picture1.circle
(ox,
oy),
5
picture1.fillcolor
=
vbgreen
'圆周上的铰链点
picture1.circle
(xo,
yo),
4
picture1.fillcolor
=
vbred
'滑块
picture1.line
(xs,
oy
-
20)-(xs
+
30,
oy),
,
b
picture1.drawstyle
=
2
'虚线
picture1.drawwidth
=
1
'线宽1
for
i
=
0
to
9
'表示壁面的虚线
picture1.line
(i
*
4
*
orad
/
10
+
ox
+
2
*
orad,
oy)-(i
*
4
*
orad
/
10
+
ox
+
2
*
orad
+
20,
oy
+
20)
next
end
sub
private
sub
timer1_timer()
'画
draw
60,
60,
40
end
sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)