版块导航
正在加载中...
客户端APP下载
论文辅导
调剂小程序
登录
注册
帖子
帖子
用户
本版
应《网络安全法》要求,自2017年10月1日起,未进行实名认证将不得使用互联网跟帖服务。为保障您的帐号能够正常使用,请尽快对帐号进行手机号验证,感谢您的理解与支持!
24小时热门版块排行榜
>
论坛更新日志
(3085)
>
文献求助
(227)
>
虫友互识
(188)
>
导师招生
(187)
>
考博
(87)
>
基金申请
(81)
>
考研
(70)
>
论文投稿
(65)
>
招聘信息布告栏
(61)
>
休闲灌水
(57)
>
硕博家园
(50)
>
博后之家
(34)
>
教师之家
(31)
>
论文道贺祈福
(23)
>
物理
(22)
>
找工作
(21)
小木虫论坛-学术科研互动平台
»
计算模拟区
»
仿真模拟
»
MATLAB
»
Matlab交互式三维齿轮绘制和动画演示(非原创 感觉不错 拿来和大家一起分享)
5
1/1
返回列表
查看: 7818 | 回复: 62
只看楼主
@他人
存档
新回复提醒
(忽略)
收藏
在APP中查看
【奖励】
本帖被评价52次,作者qudingfeng增加金币
39.2
个
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖
qudingfeng
至尊木虫
(知名作家)
应助: 10
(幼儿园)
金币: 10114.3
帖子: 9791
在线: 853.2小时
虫号: 1575311
[
资源
]
Matlab交互式三维齿轮绘制和动画演示(非原创 感觉不错 拿来和大家一起分享)
CODE:
function gear3d(varargin)
%GEAR3D GUI example of 3D gear.
% GEAR3D will pop up a GUI example of 3D gear. The gear rolls on a geared
% ground based on the mouse location. It uses the x-location of the mouse
% pointer for the gear location. Use the arrow keys to change the view.
% Press SPACEBAR to reset the view. This was inspired by Mike Agostini's
% 3D Clock submission in FEX:
%
%
% The gear is made of 2 surface objects, and the ground is a single surface
% object. Since the moving part (gear) only contains 2 objects, the
% animation update is quite smooth. It uses OpenGL rendering.
%
% GEAR3D accepts 3 optional arguments that specify the number of teeth on the
% gear, number of spokes, and the gear ratio between the ground and the gear.
%
% Example:
% GEAR3D('teeth', 30) - default is 50.
% GEAR3D('spokes', 4) - default is 8.
% GEAR3D('ratio', 2) - default is 3. This also determines how big
% the ground radius is.
% Only positive integers are allowed.
%
% This has no practical use. I made it as an exercise for 3d animation.
% You have been warned. This was created in R13SP1, so nested function is
% not utilized. Nested function will improve how surface data are passed
% between functions.
%
% VERSIONS:
% v1.0 - first version
% v1.1 - fixed gear meshing problem. (Feb 2, 2006)
% v1.2 - changed to pass parameters instead of using handles structure
% (for speed). also inlined the stripped down version of the ROTATE
% function to speed up animation (Feb 25, 2006)
%
% Jiro Doke
% Feb 3, 2006
%--------------------------------------------------------------------------
% Default values
%--------------------------------------------------------------------------
% Number of teeth
numteeth = 50;
% Number of spokes
numspokes = 8;
% Gear ratio
rr = 3;
%--------------------------------------------------------------------------
% Optional arguments
%--------------------------------------------------------------------------
if mod(nargin, 2) == 1
error('Optional arguments must come in pairs.');
end
if nargin
opt = varargin(1:2:end);
val = varargin(2:2:end);
validOpts = {'teeth', 'spokes', 'ratio'};
for iArg = 1:length(opt)
id = strmatch(lower(opt{iArg}), validOpts);
if isempty(id)
error('Invalid option. Valid options: ''teeth'', ''spokes'', ''ratio''');
else
switch strmatch(lower(opt{iArg}), validOpts)
case 1
if isnumeric(val{iArg}) & length(val{iArg}) == 1
numteeth = round(abs(val{iArg}));
end
case 2
if isnumeric(val{iArg}) & length(val{iArg}) == 1
numspokes = round(abs(val{iArg}));
end
case 3
if isnumeric(val{iArg}) & length(val{iArg}) == 1
rr = round(abs(val{iArg}));
end
end
end
end
end
%--------------------------------------------------------------------------
% Construct gear and ground
%--------------------------------------------------------------------------
% Gear part radii
r1 = 1;
r2 = 3;
r3 = 10;
r4 = 11;
r5 = 13;
r6 = 12;
% Radius to the center of gear teeth
r = (r5 + r6) / 2;
% Height of gear teeth
h = r5 - r6;
% Radius to the center of ground teeth
l = r * rr;
% Ground radii
l1 = l - h/2;
l2 = l + h/2;
l3 = l2 + 2;
% Gear
[x0,y0,z0] = cylinder([r6], numteeth*4); % teeth groove
[x1,y1,z1] = cylinder([r1, r1, r2, r2, r1], numteeth*4); % spokes
[x2,y2,z2] = cylinder([r3, r3, r4, r4, r5, r5, r4, r4, r3], numteeth*4); % gear teeth
z1([1, 4, 5], :) = 2;
z1(2:3, :) = -2;
z2([1, 8, 9], :) = 2;
z2(2:3, :) = -2;
z2(4:5, :) = -1;
z2(6:7, :) = 1;
x2(5:6,1:4:end) = x0(1:2,1:4:end);
x2(5:6,2:4:end) = x0(1:2,2:4:end);
y2(5:6,1:4:end) = y0(1:2,1:4:end);
y2(5:6,2:4:end) = y0(1:2,2:4:end);
% Spoke
interval = round(length(x1) / numspokes);
for id = 1:4
x1(3:4, id:interval:end) = x2(1:2, id:interval:end);
y1(3:4, id:interval:end) = y2(1:2, id:interval:end);
end
% Ground
[x3, y3, z3] = cylinder([l2, l2, l3, l3, l2], numteeth * rr * 4);
[x4, y4, z4] = cylinder(l1, numteeth * rr * 4);
z3([1 4 5], :) = 4;
z3([2 3], :) = -4;
x3([1 2 5], 1:4:end) = x4([1 1 1], 1:4:end);
x3([1 2 5], 2:4:end) = x4([1 1 1], 2:4:end);
y3([1 2 5], 1:4:end) = y4([1 1 1], 1:4:end);
y3([1 2 5], 2:4:end) = y4([1 1 1], 2:4:end);
% Make ground a half circle
len = round(length(x3) / 2);
x3(:, len:end) = [];
y3(:, len:end) = [];
z3(:, len:end) = [];
%--------------------------------------------------------------------------
% GUI
%--------------------------------------------------------------------------
% Create figure;
fH = findobj('Type', 'figure', 'Tag', 'solidmodelGUI');
if ishandle(fH)
close(fH);
end
fH = figure(...
'Name' , sprintf('3D Gear: View = [%3.0f, %3.0f]', 0, -50), ...
'NumberTitle', 'off', ...
'Units' , 'normalized', ...
'Position' , [.1, .1, .8, .8], ...
'Visible' , 'off', ...
'Tag' , 'solidmodelGUI');
axes(...
'Units' , 'normalized', ...
'Position', [0, .9, 1, .1], ...
'XLim' , [-1, 1], ...
'YLim' , [-1, 1], ...
'Visible' , 'off');
text(0, 0, ...
{'Move the mouse left and right within the figure window to move the gear.',...
'Use ARROW keys to change the view. SPACE to reset view.'}, ...
'HorizontalAlignment' , 'center', ...
'VerticalAlignment' , 'middle', ...
'Color' , 'red');
axH = axes('Units', 'normalized', ...
'Position', [0, 0, 1, .9]);
% Gear
%
% Spokes
gearH(1) = surface(x1,y1,z1, ...
'EdgeColor', [.3, .3, .3], ...
'EdgeAlpha', 0, ...
'FaceColor', [.5, .5, 1]);
% Gear Teeth
gearH(2) = surface(x2,y2,z2, ...
'EdgeColor', [.3, .3, .3], ...
'EdgeAlpha', .1, ...
'FaceColor', [.5, .5, 1]);
% Ground
surface(x3,y3,z3, ...
'EdgeColor', [.3, .3, .3], ...
'EdgeAlpha', .1, ...
'FaceColor', [.5, 1, .5], ...
'FaceAlpha', .5);
set(axH, 'View', [0, -50]);
axis equal manual off;
set(axH, 'CameraViewAngleMode', 'manual');
% Add lighting
light('Position', [50 , 0, -20]);
light('Position', [-50, 0, -20]);
% Calculate size once and pass in as parameter
sz1 = size(x1);
sz2 = size(x2);
set(fH, ...
'Visible' , 'on', ...
'KeyPressFcn' , {@myKeyPressFcn, axH}, ...
'WindowButtonMotionFcn', {@myMotionFcn, gearH, x1, x2, y1, y2, r, l, sz1, sz2});
% Set initial position of gear
myMotionFcn(gcf, [], gearH, x1, x2, y1, y2, r, l, sz1, sz2);
%--------------------------------------------------------------------------
% myKeyPressFcn - process key presses to rotate view
%--------------------------------------------------------------------------
function myKeyPressFcn(obj, edata, axH)
k = get(obj, 'CurrentKey');
aZeL = get(axH, 'View');
switch lower(k)
case 'uparrow'
aZeL(2) = min([aZeL(2) + 10, 90]);
case 'downarrow'
% -90 doesn't work well when rotated left or right
aZeL(2) = max([aZeL(2) - 10, -89.9999]);
case 'leftarrow'
aZeL(1) = max([aZeL(1) - 10, -90]);
case 'rightarrow'
aZeL(1) = min([aZeL(1) + 10, 90]);
case 'space'
aZeL = [0, -50];
end
set(axH, 'View', aZeL);
set(obj, 'Name', sprintf('3D Gear: View = [%3.0f, %3.0f]', aZeL));
%--------------------------------------------------------------------------
% myMotionFcn - move mouse to move gear
%--------------------------------------------------------------------------
function myMotionFcn(obj, edata, gearH, x1, x2, y1, y2, r, l, sz1, sz2)
pt = get(obj, 'CurrentPoint');
d = l - r;
% Get center location of gear
x0 = -d + pt(1) * d * 2;
y0 = sqrt(abs(d^2 - x0^2));
% Get amount of gear rotation
th1 = atan2(x0, y0) - pi/2;
th = (th1 - (th1 * (l / r)));
%--------------------------------------------------------------------------
% Rotate gear (from ROTATE)
%--------------------------------------------------------------------------
% Calculate rotation matrix
cosa = cos(-th);
sina = sin(-th);
rot = [cosa, -sina; sina, cosa]';
newxy1 = [x1(:), y1(:)];
newxy2 = [x2(:), y2(:)];
newxy1 = newxy1 * rot;
newxy2 = newxy2 * rot;
newx1 = x0 + reshape(newxy1(:, 1), sz1);
newy1 = y0 + reshape(newxy1(:, 2), sz1);
newx2 = x0 + reshape(newxy2(:, 1), sz2);
newy2 = y0 + reshape(newxy2(:, 2), sz2);
% Set new position for the gear
set(gearH, {'XData', 'YData'}, {newx1, newy1; newx2, newy2});
[
Last edited by xiegangmai on 2012-9-18 at 10:13
]
回复此楼
» 本帖附件资源列表
欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
附件 1 :
intergear.m
2012-09-18 10:02:17, 8.55 K
» 收录本帖的淘帖专辑推荐
matlab学习专辑
模拟与仿真
杂货铺子
软件与检测
我喜欢
MATLAB
» 猜你喜欢
国自然面上和省基金B类撒花
已经有18人回复
有没有学校收留
已经有3人回复
312求调剂
已经有3人回复
华师大读博
已经有5人回复
又一批高校组建人工智能学院 师资行吗 不是骗人吗
已经有5人回复
急需审稿人!!!
已经有3人回复
申博/考博
已经有8人回复
295分求调剂
已经有6人回复
085600材料与化工调剂
已经有6人回复
有没有接收比较快的sci期刊呀,最好在一个月之内的,研三孩子求毕业
已经有7人回复
» 本主题相关价值贴推荐,对您同样有帮助:
大家看一下这个反应是不是写错了
已经有4人回复
[转载]MATLAB操作EXCEL文件,感觉不错,转载下方便下次使用!
已经有8人回复
齿轮热处理的仿真技术
已经有2人回复
1楼
2012-09-18 10:02:37
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
yulinboylove
铜虫
(初入文坛)
应助: 0
(幼儿园)
金币: 88.5
帖子: 15
在线: 2.9小时
虫号: 3042512
这个function怎么显示是错误的?
赞
一下
回复此楼
高级回复
30楼
2014-04-01 11:16:09
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
查看全部 63 个回答
qudingfeng
至尊木虫
(知名作家)
应助: 10
(幼儿园)
金币: 10114.3
帖子: 9791
在线: 853.2小时
虫号: 1575311
贴的程序有点问题 表情不知怎么被我弄上去了 大家下载附件吧
赞
一下
(2人)
回复此楼
2楼
2012-09-18 10:04:48
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
zyszby
铁虫
(初入文坛)
应助: 0
(幼儿园)
金币: 104
帖子: 13
在线: 51.5小时
虫号: 2105580
★★★★★ 五星级,优秀推荐
谢谢楼主了。
学习齿轮中。。。
以后的方向,现在的初学者:)
赞
一下
回复此楼
8楼
2012-12-08 02:20:27
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
tanhao365
新虫
(小有名气)
应助: 0
(幼儿园)
金币: 961
帖子: 179
在线: 24.8小时
虫号: 2252885
★★★★★ 五星级,优秀推荐
贴出来的程序问题不少,下载的那个下不下来,金币不够
赞
一下
回复此楼
10楼
2013-01-21 14:35:21
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
简单回复
qudingfeng
3楼
2012-09-18 10:15
回复
huwanpeng2
4楼
2012-09-18 16:24
回复
三星好评
顶一下,感谢分享!
shizijun
5楼
2012-09-19 08:29
回复
五星好评
顶一下,感谢分享!
bingyu310
6楼
2012-09-20 16:07
回复
三星好评
顶一下,感谢分享!
roberthw6241
7楼
2012-10-01 10:17
回复
五星好评
顶一下,感谢分享!
suweihuaok
9楼
2012-12-09 14:31
回复
五星好评
顶一下,感谢分享!
dearredapple
11楼
2013-01-23 14:06
回复
五星好评
顶一下,感谢分享!
silver_cici
12楼
2013-02-23 23:11
回复
五星好评
顶一下,感谢分享!
楼小佳
13楼
2013-04-05 15:55
回复
五星好评
顶一下,感谢分享!
查看全部 63 个回答
☆ 无星级
★ 一星级
★★★ 三星级
★★★★★ 五星级
如果回帖内容含有宣传信息,请如实选中。否则帐号将被全论坛禁言
普通表情
龙
兔
虎
猫
高级回复
(可上传附件)
百度网盘
|
360云盘
|
千易网盘
|
华为网盘
在新窗口页面中打开自己喜欢的网盘网站,将文件上传后,然后将下载链接复制到帖子内容中就可以了。
最具人气热帖推荐
[查看全部]
作者
回/看
最后发表
[
基金申请
]
国自然面上和省基金B类撒花
+18
花田半亩~白
2026-04-21
18/900
2026-04-23 11:31
by
12021227
[
考研
]
有没有学校收留
+3
蒋昌鹏qtj
2026-04-20
3/150
2026-04-22 20:25
by
学员JpLReM
[
考研
]
312求调剂
+3
山河似你温柔
2026-04-22
3/150
2026-04-22 20:17
by
学员JpLReM
[
考博
]
华师大读博
+3
xq83
2026-04-22
5/250
2026-04-22 10:42
by
xq83
[
教师之家
]
又一批高校组建人工智能学院 师资行吗 不是骗人吗
+5
yexuqing
2026-04-19
5/250
2026-04-22 10:01
by
easeheart
[
考博
]
申博/考博
+4
啃面包的小书虫
2026-04-17
8/400
2026-04-21 16:26
by
啃面包的小书虫
[
考研
]
295分求调剂
+6
?要上岸?
2026-04-17
6/300
2026-04-21 08:18
by
Equinoxhua
[
考研
]
085600材料与化工调剂
5
+3
孜孜不倦2002
2026-04-19
6/300
2026-04-20 21:25
by
babero
[
论文投稿
]
有没有接收比较快的sci期刊呀,最好在一个月之内的,研三孩子求毕业
20
+4
之护着
2026-04-16
7/350
2026-04-20 15:45
by
豆豆7758
[
考研
]
337求调剂
+3
jyz04
2026-04-18
3/150
2026-04-20 12:24
by
研可安
[
考博
]
申博
+3
Xyyx.
2026-04-18
3/150
2026-04-20 10:44
by
YuY66
[
考博
]
湖南大学刘巧玲课题组2026年第二批次博士研究生招生信息
+3
南风观火
2026-04-18
5/250
2026-04-20 10:13
by
南风观火
[
考研
]
求计算机方向调剂
+3
Toffee2
2026-04-16
6/300
2026-04-19 22:37
by
ll叶
[
考研
]
294求调剂
+8
淡然654321
2026-04-17
9/450
2026-04-19 19:51
by
Equinoxhua
[
考研
]
304求调剂
+8
castLight
2026-04-16
8/400
2026-04-19 17:14
by
中豫男
[
考研
]
求调剂
+6
苦命人。。。
2026-04-18
7/350
2026-04-19 16:27
by
中豫男
[
考研
]
接受任何调剂
+6
也就是栗子
2026-04-17
7/350
2026-04-18 17:20
by
涵竹刘
[
考研
]
收到复试调剂但是去不了
+8
小蜗牛*
2026-04-16
8/400
2026-04-18 11:15
by
zixin2025
[
有机交流
]
二苯甲酮酸类衍生物
50
+3
小白爱主人
2026-04-17
6/300
2026-04-17 18:47
by
kf2781974
[
考研
]
322求调剂
+6
tekuzu
2026-04-17
6/300
2026-04-17 13:48
by
Espannnnnol
信息提示
关闭
请填处理意见
关闭
确定