سورس شبیه سازی چرخ دنده در متلب
3844 بازدید
- 1393/05/08
- دیدگاهها برای سورس شبیه سازی چرخ دنده در متلب بسته هستند
در این پست قصد ارائه سورس حرکت دو چرخ دنده داخلی(Internal Gears) به زبان متلب را داریم. با استفاده از حرکت موس شما می توانید چاخ دنده را به حرکت درآوردید. این برنامه را می توانید با سه پارامتر اجرا نمایید؛ تعیین teeth، spokes و ratio که مقادری پیش فرض هر یک از آنها بصورت زیر می باشد:
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.
خروجی این برنامه بصورت زیر می باشد:
Internal Gears Simulation in MATLAB
سورس کامل این برنامه:
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
% 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
% EngPedia.ir
% Iranian Engineering Encyclopedia
%--------------------------------------------------------------------------
% 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});
مطالب مرتبط
برچسب ها : simulate gears in matlab, چرخ دنده, چرخ دنده matlab, چرخ دنده داخلی, سورس شبیه سازی چرخ دنده در متلب
دیدگاهتان را بنویسید
بخش های مورد نیاز علامت گذاری شده اند
نشانی ایمیل منتشر نخواهد شد
مطالب جدید
- IEDScout 5.22 پایش و عیب یابی IED در شبکه
- TINA 16 تحلیل مدار آنالوگ، دیجیتال، MCU و مختلط
- EMD energyPRO 5 تحلیل سیستم های انرژی
- ADAPT PT/RC 23.0.1 تحلیل غیرخطی تیر و سازه بتنی
- RISA Section 2.1.1 تحلیل مقاطع فولادی و سازه ای
- vMix 29 تولید و پخش زنده حرفه ای
- Ampsa ADW v24 طراحی تقویتکننده RF
- Ampsa MW v24 طراحی شبکه تطبیق امپدانس RF
- DSS Professional 8.7 مدیریت و نظارت تصویری هوشمند
- PowerACOUSTICS 2026 تحلیل آکوستیک و نویز در طراحی صنعتی
مطالب پربازدید
- دانلود کتاب هیدرولیک و پنوماتیک فستو Festo فارسی
- دانلود استاندارد
- دانلود نرم افزار کلید فولاد (Key to Steel) پرتابل
- دانلود فول استاندارد ASTM بصورت رایگان
- آموزش میکروکنترلر AVR
- دانلود آنتی ویروس شورتکات (Back 2 Normal)
- دانلود جدول استاندارد DIN
- دانلود کتاب آموزش Abaqus (فارسی)
- دانلود نرم افزار MATLAB برای آندروید(MATLAB Android)
- فول استاندارد ASME (بروز)
مطالب تصادفی
- AVL Simulation Suite 2025.1 شبیهسازی سامانه خودرو و انرژی
- Genesis 2026 مدلسازی و ارزیابی منابع زمینشناسی
- نرم افزار SteinN Pro 2025 محاسبه نشست پی
- شبیه سازی ترک در ABAQUS
- BowTie Pro 3.4.5.1 تحلیل ریسک و ایمنی صنعتی
- حساب تغییرات
- کتاب Finite Element Analysis of Composite Materials using Abaqus
- بررسی مدهای ارتعاشی حسگرهای پیزوالکتریک در ترانسدیوسرهای سونار
- دانلود مجموعه سورس Hopfield Neural Network
- فرآیند آهنگری


