版块导航
正在加载中...
客户端APP下载
论文辅导
申博辅导
登录
注册
帖子
帖子
用户
本版
应《网络安全法》要求,自2017年10月1日起,未进行实名认证将不得使用互联网跟帖服务。为保障您的帐号能够正常使用,请尽快对帐号进行手机号验证,感谢您的理解与支持!
24小时热门版块排行榜
>
论坛更新日志
(3164)
>
虫友互识
(218)
>
导师招生
(198)
>
文献求助
(187)
>
博后之家
(115)
>
硕博家园
(104)
>
休闲灌水
(99)
>
论文投稿
(82)
>
考博
(71)
>
基金申请
(56)
>
招聘信息布告栏
(36)
>
教师之家
(32)
>
公派出国
(30)
>
考研
(28)
>
找工作
(20)
>
绿色求助(高悬赏)
(17)
小木虫论坛-学术科研互动平台
»
计算模拟区
»
仿真模拟
»
MATLAB
»
Matlab交互式三维齿轮绘制和动画演示(非原创 感觉不错 拿来和大家一起分享)
5
2/1
返回列表
查看: 7198 | 回复: 62
只看楼主
@他人
存档
新回复提醒
(忽略)
收藏
在APP中查看
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖
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
» 猜你喜欢
申请2026年博士
已经有5人回复
天津工业大学郑柳春团队欢迎化学化工、高分子化学或有机合成方向的博士生和硕士生加入
已经有5人回复
寻求一种能扛住强氧化性腐蚀性的容器密封件
已经有6人回复
到新单位后,换了新的研究方向,没有团队,持续积累2区以上论文,能申请到面上吗
已经有6人回复
2025冷门绝学什么时候出结果
已经有7人回复
请问有评职称,把科研教学业绩算分排序的高校吗
已经有6人回复
Bioresource Technology期刊,第一次返修的时候被退回好几次了
已经有7人回复
请问哪里可以有青B申请的本子可以借鉴一下。
已经有4人回复
请问下大家为什么这个铃木偶联几乎不反应呢
已经有5人回复
康复大学泰山学者周祺惠团队招收博士研究生
已经有6人回复
1楼
2012-09-18 10:02:37
已阅
回复此楼
关注TA
给TA发消息
送TA红花
TA的回帖
Selfhelp01
捐助贵宾
(初入文坛)
应助: 0
(幼儿园)
金币: 64
帖子: 2
在线: 1.1小时
虫号: 8025994
★★★★★ 五星级,优秀推荐
顶一次啊,感谢分享
回复此楼
高级回复
53楼
2018-03-27 18:01:49
已阅
回复此楼
关注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云盘
|
千易网盘
|
华为网盘
在新窗口页面中打开自己喜欢的网盘网站,将文件上传后,然后将下载链接复制到帖子内容中就可以了。
信息提示
关闭
请填处理意见
关闭
确定