File:Unnecessarily complicated gears a.gif
Summary[edit]
Description | |
Date | |
Source | Own work |
Author | Jahobr |
|
Matlab
function unnecessarily_complicated_gears()
% source code for drawing unnecessarily complicated gearing
% the shape of the gears is not precise. It is a hack job that produces a GIF and a SVG
%
% 2017-06-20 Jahobr
teethSun = 48; %
teethPlan = 12; %
teethRing = teethSun+teethPlan*2;
nPlan = 12; % number of planets
teethSun_top = 24;
teethHub_spoked = 60;
teethHub_back = 24;
teethBigSpoke = 96;
teethRackTrans_Bottom = 25;
teethRackTrans_Top = 25/5*4;
teethRackDriver = 16;
modul_Epicyclic = 1;
modul_Hub_Spoke = 1.8;
modul_Sun_Hub = 1.5;
modul_LL = 0.8;
modul_top = 0.9;
modul_Rack = 1.4;
col.carrier = roundToUINT8pos([0.1 0.7 0.1 ]); % green
col.sun = roundToUINT8pos([0.95 0.65 0 ]); % yellow (obviously)
col.palnet = roundToUINT8pos([0.2 0.2 1 ]); % blue (obviously)
col.ring = roundToUINT8pos([1 0.2 0.2 ]); % red
col.hub = roundToUINT8pos([0.6 0.2 0.8 ]); % violet
col.spoke = roundToUINT8pos([0.5 0.5 0.5 ]); %
col.rackTrans = roundToUINT8pos([0.4 0.24 0.08]); %
col.rack = roundToUINT8pos([1 0.5 0.2 ]); %
col.rackDrive = roundToUINT8pos([0.8 0.3 0.2 ]); %
col.LL_1 = roundToUINT8pos([0.4 0.6 0.6 ]); %
col.LL_2 = roundToUINT8pos([0.3 0.6 0.8 ]); %
col.top = roundToUINT8pos([0.5 0.7 1 ]); %
diameterSun = modul_Epicyclic.*teethSun;
diameterPlan = modul_Epicyclic.*teethPlan;
diameterCarr = diameterSun+diameterPlan;
dist_Sun_Hub = mean([modul_Sun_Hub*teethSun_top, modul_Sun_Hub*teethHub_spoked]);
centerHub = [dist_Sun_Hub*cosd(60) -dist_Sun_Hub*sind(60)];
dist_Hub_Spoke = mean([modul_Hub_Spoke*teethHub_back, modul_Hub_Spoke*teethBigSpoke]) ;
centerSpoke = [dist_Hub_Spoke*cosd(60) +dist_Hub_Spoke*sind(60)]+centerHub;
dist_Hub_RackTrans = mean([modul_Sun_Hub*teethHub_spoked, modul_Sun_Hub*teethRackTrans_Bottom]);
centerRackTrans = [dist_Hub_RackTrans*cosd(53) +dist_Hub_RackTrans*sind(53)]+centerHub;
dist_RackTrans_col.rackDriver = mean([modul_Rack*teethRackTrans_Top, modul_Rack*teethRackDriver ]);
centerRackDriver = [dist_RackTrans_col.rackDriver*cosd(55) -dist_RackTrans_col.rackDriver*sind(55)]+centerRackTrans;
[pathstr,fname] = fileparts(which(mfilename)); % save files under the same name and at file location
xlimValues = [-20 100];
ylimValues = [-60 40];
xRange = xlimValues(2)-xlimValues(1);
yRange = ylimValues(2)-ylimValues(1);
ySize = 500; % pixel
xSize = round(ySize/yRange*xRange); % pixel
scaleReduction = 2; % reduction for nice antialiasing
linW = 2.5; % LineWidth
nFrames = 170;
figHandle = figure(15674455); clf
set(figHandle, 'Units','pixel');
set(figHandle, 'position',[1 1 xSize*scaleReduction ySize*scaleReduction]); % big start image for antialiasing later [x y width height]
%set(figHandle, 'GraphicsSmoothing','on') % requires at least version 2014b
axesHandle = axes; hold(axesHandle,'on');
set(axesHandle,'position',[0 0 1 1]); % stretch axis bigger as figure, [x y width height]
set(axesHandle,'XTick',NaN) % get rid of ticks
set(axesHandle,'YTick',NaN) % get rid of ticks
set(axesHandle,'TickLength',[0 0]) % get rid of ticks
set(axesHandle,'YColor',[1 1 1]) % remove outline
set(axesHandle,'XColor',[1 1 1]) % remove outlinexlim(xli);
xlim(xlimValues);ylim(ylimValues);
axis equal; drawnow;
angleCarrier = -linspace(0,pi*2/nPlan,nFrames+1); % define gear position in frames
angleCarrier = angleCarrier(1:end-1); % remove last frame, it would be double
anglePlan = angleCarrier.*( teethSun/teethPlan+1 ); % gear ratio
anglePlan = -anglePlan + (pi/teethPlan); % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleSun = angleCarrier.* (1+teethRing/teethSun); % gear ratio
angleSun = angleSun + 0; % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleRing = zeros(size(anglePlan));
reducedRGBimage = uint8(ones(ySize,xSize,3,nFrames)); % allocate
for iFrame = 1:nFrames
cla(axesHandle);xlim(xlimValues);ylim(ylimValues); % fresh frame
%% background wheels
% Hub background wheel 24 teeth rotates 2, interacts with spoked
drawCogWheel(centerHub,teethHub_back ,modul_Hub_Spoke,... % center, number of teeth, modul
col.hub*0.6, linW,... % color, linewidth
-angleSun(iFrame)/2.5,... % angle of rotaion
NaN, 1, 3, 1); % nSpoke, spokeW, sideOffset, shaftDiameter
% fine Spoked wheel 96 teeth rotates 2
drawCogWheel(centerSpoke,teethBigSpoke, modul_Hub_Spoke,... % center, number of teeth, modul
col.spoke, linW,... % color, linewidth
angleSun(iFrame)/2.5/4 + pi/teethBigSpoke,... % angle of rotaion
teethBigSpoke/2, 0.5, 0, 13.2); % nSpoke, spokeW, sideOffset, shaftDiameter
%% %%%%%%%%%% Epicyclic_Gearing %%%%%%%%%%%%%%%%%%%%%
% ring
drawRingGear(teethRing,modul_Epicyclic,col.ring,linW,angleRing(iFrame))
% sun
drawCogWheel([0 0],teethSun ,modul_Epicyclic,... % center, number of teeth, modul
col.sun, linW,... % color, linewidth
angleSun(iFrame),... % angle of rotaion
NaN, 0, 0, 0); % nSpoke, spokeW, sideOffset, shaftDiameter
% planets
angPlan = linspace(0,2*pi,nPlan+1);
angPlan = angPlan(1:end-1);
for iPlan = angPlan
[X,Y] = pol2cart(iPlan+angleCarrier(iFrame) ,diameterCarr/2);
drawCogWheel([X,Y],teethPlan,modul_Epicyclic,... % center, number of teeth, modul
col.palnet, linW,... % color, linewidth
anglePlan(iFrame),... % angle of rotaion
NaN, 0, 0, 0); % nSpoke, spokeW, sideOffset, shaftDiameter
end
% carrier
angCarr = linspace(0,2*pi,nPlan+1);
[X,Y] = pol2cart([angCarr fliplr(angCarr)]+angleCarrier(iFrame) ,[ones(size(angCarr))*diameterCarr/2.07 ones(size(angCarr))* diameterCarr/1.93]);
patch(X,Y,col.carrier,'EdgeColor',[0 0 0],'LineWidth',linW) % full outer disc
for iPlan = angPlan
[X,Y] = pol2cart(iPlan+angleCarrier(iFrame) ,diameterCarr/2);
circlePatch(X,Y,diameterPlan*0.25,col.carrier,linW);
circlePatch(X,Y,diameterPlan*0.15,col.palnet, linW);
end
%% connection Epicyclic Gearing and hub
% 24 teeth, rotates 5 teeth
drawCogWheel([0 0],teethSun_top ,modul_Sun_Hub,... % center, number of teeth, modul
1-(1-col.sun)*0.5, linW,... % color, linewidth
angleSun(iFrame),... % angle of rotaion
NaN, 0, 0, 3); % nSpoke, spokeW, sideOffset, shaftDiameter
% spoked hub wheel: 60 teeth; rotates 5
drawCogWheel(centerHub,teethHub_spoked ,modul_Sun_Hub,... % center, number of teeth, modul
col.hub, linW,... % color, linewidth
-angleSun(iFrame)/2.5 +pi/teethHub_spoked,... % angle of rotaion
teethSun/2*2.5/5,... % 12 nSpoke,
1, 5.5, 7); % spokeW, sideOffset, shaftDiameter
%% chain of wheels on the Top
% on top big spoked (wheel 96 teeth rotates 2) 48 teeth rotates 1
drawCogWheel(centerSpoke,48 ,modul_top,... % center, number of teeth, modul
1-(1-col.spoke)*0.7, linW,... % color, linewidth
angleSun(iFrame)/2.5/4+0.2,... % angle of rotaion
NaN, 1, 0, 7); % nSpoke, spokeW, sideOffset, shaftDiameter
% top idler , meshing with small wheel big spoked; 17 teeth rotates 1
drawCogWheel([57.35 31],17 ,modul_top,... % center, number of teeth, modul
col.top, linW,... % color, linewidth
-angleSun(iFrame)/2.5/4 * 48/17 - 0.067,... % angle of rotaion
NaN, 1, 0, 3); % nSpoke, spokeW, sideOffset, shaftDiameter
% last on top, meshing with idler; 23 teeth rotates 1
drawCogWheel([42.34 41],23 ,modul_top,... % center, number of teeth, modul
col.top*0.8, linW,... % color, linewidth
angleSun(iFrame)/2.5/4 * 48/23 +0.12,... % angle of rotaion
NaN, 1, 0, 3); % nSpoke, spokeW, sideOffset, shaftDiameter
%% Rack
% Rack-Transmission; meshes in Hub-spoked 25 teeth rotates 5
drawCogWheel(centerRackTrans,teethRackTrans_Bottom,modul_Sun_Hub,... % center, number of teeth, modul
col.rackTrans, linW,... % color, linewidth
angleSun(iFrame)/teethRackTrans_Bottom*teethSun_top +0.003,... % angle of rotaion
NaN, 1, 0, 0); % nSpoke, spokeW, sideOffset, shaftDiameter
% Rack-Transmission; meshes in Rack-driver; 15 teeth rotates 3
drawCogWheel(centerRackTrans,teethRackTrans_Top,modul_Rack,... % center, number of teeth, modul
1-(1-col.rackTrans)*0.7, linW,... % color, linewidth
angleSun(iFrame)/teethRackTrans_Bottom*teethSun_top +0.157,... % angle of rotaion
NaN, 1, 0, 2.5); % nSpoke, spokeW, sideOffset, shaftDiameter
% Rack-driver; idler between Rack-Transmission and Rack
drawCogWheel(centerRackDriver,teethRackDriver ,modul_Rack,... % center, number of teeth, modul
col.rackDrive, linW,... % color, linewidth
-angleSun(iFrame)/teethRackTrans_Bottom*teethSun_top *15/12 +pi/teethRackDriver ,... % angle of rotaion
NaN, 0.5, 0, 2); % nSpoke, spokeW, sideOffset, shaftDiameter
drawRack([centerRackDriver(1)+modul_Rack*teethRackDriver /2 centerRackDriver(2)],50,modul_Rack,col.rack,linW,-angleSun(iFrame)/teethRackTrans_Bottom*teethSun_top *modul_Rack/2*teethRackTrans_Top)
%% lower left
% on top of hub; rotates 3 teeth
drawCogWheel(centerHub,36 ,modul_LL,... % center, number of teeth, modul
1-(1-col.hub)*0.9, linW,... % color, linewidth
-angleSun(iFrame)/2.5,... % angle of rotaion
NaN, 1, 3, 9); % nSpoke, spokeW, sideOffset, shaftDiameter
% next to hub; lower left trasmission; bottom wheel; rotates 3 teeth
drawCogWheel([centerHub(1)-28.8 centerHub(2)],36 ,modul_LL,... % center, number of teeth, modul
col.LL_1*0.5, linW,... % color, linewidth
angleSun(iFrame)/2.5 +pi/36,... % angle of rotaion
NaN, 1, 0, 1); % nSpoke, spokeW, sideOffset, shaftDiameter
% lower left trasmission; top wheel; rotates 2 teeth
drawCogWheel([centerHub(1)-28.8 centerHub(2)],24 ,modul_LL,... % center, number of teeth, modul
col.LL_1, linW,... % color, linewidth
angleSun(iFrame)/2.5 ,... % angle of rotaion
NaN, 1, 0, 4); % nSpoke, spokeW, sideOffset, shaftDiameter
% lower left wheel; rotates 2 teeth; rotates 1 spoke
drawCogWheel([centerHub(1)-57.6 centerHub(2)],48 ,modul_LL,... % center, number of teeth, modul
col.LL_2, linW,... % color, linewidth
-angleSun(iFrame)/2.5 /2 +pi/48,... % angle of rotaion
24, 1, 0, 10); % nSpoke, spokeW, sideOffset, shaftDiameter
%% save animation
xlim(xlimValues); ylim(ylimValues); drawnow
f = getframe(figHandle);
reducedRGBimage(:,:,:,iFrame) = imReduceSize(f.cdata,scaleReduction); % the size reduction: adds antialiasing
% if iFrame == 10 % SVG
% if ~isempty(which('plot2svg'))
% plot2svg(fullfile(pathstr, [fname '_a.svg']),figHandle) % by Juerg Schwizer
% else
% disp('plot2svg.m not available; see http://www.zhinst.com/blogs/schwizer/');
% end
% end
end
map = createImMap(reducedRGBimage,128,[0 0 0;1 1 1;struct2map(col)]); % colormap
im = uint8(ones(ySize,xSize,1,nFrames)); % allocate
for iFrame = 1:nFrames
im(:,:,1,iFrame) = rgb2ind(reducedRGBimage(:,:,:,iFrame),map,'nodither');
end
imwrite(im,map,fullfile(pathstr, [fname '_a.gif']),'DelayTime',1/25,'LoopCount',inf) % save gif
disp([fname '.gif has ' num2str(numel(im)/10^6 ,4) ' Megapixels']) % Category:Animated GIF files exceeding the 50 MP limit
function drawCogWheel(center,toothNumber,modul,colFilling,linW,startOffset,nSpoke,spokeW,sideOffset,shaftDia)
% DRAWTOOTHEDWHEEL - draw a simple Toothed Wheel
% Input:
% center: [x y]
% toothNumber: scalar
% modul: scalar tooth "size"
% colFilling: color of filling [r g b]
% linW: LineWidth (scalar)
% startOffset: start rotation (scalar)[rad]
% nSpoke: number of spokes; NaN for filled wheel (scalar integer)
% spokeW: spoke width [moduls]
% sideOffset: spoke side offset [moduls]
% shaftDia: inner shaft diameter [moduls]
effectiveRadius = modul*toothNumber/2; % effective effectiveRadius
outsideRadius = effectiveRadius+1* modul; % +---+ +---+
upperRisingRadius = effectiveRadius+0.5*modul; % / \ / \
% effective Radius % / \ / \
lowerRisingRadius = effectiveRadius-0.5*modul; % I I I I
rootRadius = effectiveRadius-1.1*modul; % + - - - + + - - - + +
angleBetweenTeeth = 2*pi/toothNumber; % angle between 2 teeth
angleOffPoints = (0:angleBetweenTeeth/16:(2*pi));
angleOffPoints = angleOffPoints+startOffset; % apply rotation offset
angleOffPoints(7:16:end) = angleOffPoints(7:16:end) + 1/toothNumber^1.2; % hack to create smaller tooth tip
angleOffPoints(11:16:end) = angleOffPoints(11:16:end) - 1/toothNumber^1.2; % hack to create smaller tooth tip
angleOffPoints(8:16:end) = (angleOffPoints(7:16:end) + angleOffPoints(9:16:end))/2; % shift the neighbouring tip point in accordingly
angleOffPoints(10:16:end) = (angleOffPoints(11:16:end) + angleOffPoints(9:16:end))/2; % shift the neighbouring tip point in accordingly
angleOffPoints(6:16:end) = angleOffPoints(6:16:end) + 1/toothNumber^1.7; % hack to create slender upperRisingRadius
angleOffPoints(12:16:end) = angleOffPoints(12:16:end) - 1/toothNumber^1.7; % hack to create slender upperRisingRadius
radiusOffPoints = angleOffPoints; % allocate with correct site
radiusOffPoints(1:16:end) = rootRadius; % center bottom I
radiusOffPoints(2:16:end) = rootRadius; % left bottom I
radiusOffPoints(3:16:end) = rootRadius; % left bottom corner +
radiusOffPoints(4:16:end) = lowerRisingRadius; % lower rising bottom \
radiusOffPoints(5:16:end) = effectiveRadius; % rising edge \
radiusOffPoints(6:16:end) = upperRisingRadius; % upper rising edge \
radiusOffPoints(7:16:end) = outsideRadius; % right top corner +
radiusOffPoints(8:16:end) = outsideRadius; % right top I
radiusOffPoints(9:16:end) = outsideRadius; % center top I
radiusOffPoints(10:16:end) = outsideRadius; % left top I
radiusOffPoints(11:16:end) = outsideRadius; % left top corner +
radiusOffPoints(12:16:end) = upperRisingRadius; % upper falling edge /
radiusOffPoints(13:16:end) = effectiveRadius; % falling edge /
radiusOffPoints(14:16:end) = lowerRisingRadius; % lower falling edge /
radiusOffPoints(15:16:end) = rootRadius; % right bottom corner +
radiusOffPoints(16:16:end) = rootRadius; % right bottom I
[X,Y] = pol2cart(angleOffPoints,radiusOffPoints);
X = X+center(1); % center offset
Y = Y+center(2); % center offset
if ~isnan(nSpoke)
for iSpoke = 1:nSpoke
Xs = ([-1 1 1 -1]+sideOffset)*modul*spokeW;
Ys = [ 1 1 0 0]*(rootRadius-1*modul);
[Xs,Ys] = rotateCordiantes(Xs,Ys,2*pi/nSpoke*iSpoke+startOffset);% apply rotation
Xs = Xs+center(1); % center offset
Ys = Ys+center(2); % center offset
patch(Xs,Ys,colFilling*0.85,'EdgeColor',[0 0 0],'LineWidth',linW)
end
[Xc,Yc] = pol2cart(angleOffPoints,effectiveRadius-3*modul);
Xc = Xc+center(1); % center offset
Yc = Yc+center(2); % center offset
[Xc,Yc] = poly2cw(Xc,Yc);
[X,Y] = poly2cw(X,Y);
[Xb,Yb] = polybool('subtraction', X,Y,Xc,Yc);
Xb = Xb(~isnan(Xb)); % notNaN
Yb = Yb(~isnan(Yb)); % notNaN
patch(Xb,Yb,colFilling,'EdgeColor','none')
plot(X, Y, 'linewidth',linW,'color',[0 0 0]); % extra line
plot(Xc,Yc,'linewidth',linW,'color',[0 0 0]); % extra line
else % filled
patch(X,Y,colFilling,'EdgeColor',[0 0 0],'LineWidth',linW)
end
if and(~isnan(shaftDia),shaftDia>0)
circlePatch(center(1),center(2),shaftDia*modul,1-(1-colFilling)*0.85,linW);
end
% % effective Radius
% [X,Y] = pol2cart(angleOffPoints,effectiveRadius);
% X = X+center(1); % center offset
% Y = Y+center(2); % center offset
% plot(X,Y,'-.','color',[0 0 0]);
function [x,y] = rotateCordiantes(x,y,anglee)
% x coordinates of the center
% y coordinates of the center
% anglee angle of rotation in [rad]
rotM = [cos(anglee) -sin(anglee); sin(anglee) cos(anglee)];
x_y = rotM*[x(:)';y(:)'];
x = x_y(1,:);
y = x_y(2,:);
function drawRack(center,toothNumber,modul,col,linW,startOffset)
% x coordinates of the center
% y coordinates of the center
% r is the radius of the circle
% col patch color
% linW LineWidth
% startOffset initial shift
y = (0:toothNumber*8-2)*pi*modul/8;
y = y-mean(y)+center(2)+startOffset;
x = ones(size(y))*center(1);
x(1:8:end) = x(1:8:end)+1.1*modul; % + I
x(2:8:end) = x(2:8:end); % / I
x(3:8:end) = x(3:8:end)-0.9*modul; % + I
x(4:8:end) = x(4:8:end)-0.9*modul; % I I
x(5:8:end) = x(5:8:end)-0.9*modul; % + I
x(6:8:end) = x(6:8:end); % \ I
x(7:8:end) = x(7:8:end)+1.1*modul; % + I
x(8:8:end) = x(8:8:end)+1.1*modul; % I I
y(3:8:end) = y(3:8:end)+0.08*modul; %
y(5:8:end) = y(5:8:end)-0.08*modul; %
y = [y(1) y y(end)];
x = [x(1)+5*modul x x(end)+5*modul];
patch(x,y,col,'EdgeColor',[0 0 0],'LineWidth',linW);
function h = circlePatch(x,y,r,col,linW)
% x coordinates of the center
% y coordinates of the center
% r is the radius of the circle
% col patch color
% linW LineWidth
angleOffPoints = linspace(0,2*pi,200);
xc = x + r*cos(angleOffPoints);
yc = y + r*sin(angleOffPoints);
% h = plot(xc,yc,'color',col,'LineWidth',linW,'LineStyle',sty);
h = patch(xc,yc,col,'EdgeColor',[0 0 0],'LineWidth',linW);
function drawRingGear(toothNumber,modul,colFilling,linW,startOffset)
% subfunction for the outer static gear
% toothNumber: scalar
% modul: scalar tooth "size"
% colFilling: color of filling [r g b]
% linW: LineWidth (scalar)
% startOffset: start rotation (scalar)[rad]
effectiveRadius = modul*toothNumber/2; % effective effectiveRadius
outsideRadius = effectiveRadius-1* modul; % +---+ +---+
upperRisingRadius = effectiveRadius-0.5*modul; % / \ / \
% effective Radius % / \ / \
lowerRisingRadius = effectiveRadius+0.5*modul; % I I I I
rootRadius = effectiveRadius+1.1*modul; % + - - - + + - - - + +
angleBetweenTeeth = 2*pi/toothNumber; % angle between 2 teeth
angleOffPoints = (0:angleBetweenTeeth/16:(2*pi));
angleOffPoints = angleOffPoints+startOffset; % apply rotation offset
%% outerEdge
maxRadius = rootRadius*1.2; % definition of outer line
[Xout,Yout] = pol2cart(angleOffPoints,maxRadius);
% plot(axesHandle,X,Y,'linewidth',2,'color',[0 0 0]); %
%% inner teeth
radiusOffPoints = angleOffPoints; % init
angleOffPoints( 7:16:end) = angleOffPoints(7:16:end) + 1/toothNumber^1.2; % hack to create smaller tooth tip
angleOffPoints(11:16:end) = angleOffPoints(11:16:end) - 1/toothNumber^1.2; % hack to create smaller tooth tip
angleOffPoints( 8:16:end) = (angleOffPoints(7:16:end) + angleOffPoints(9:16:end))/2; % shift the neighbouring tip point in accordingly
angleOffPoints(10:16:end) = (angleOffPoints(11:16:end) + angleOffPoints(9:16:end))/2; % shift the neighbouring tip point in accordingly
angleOffPoints( 6:16:end) = angleOffPoints(6:16:end) + 1/toothNumber^1.7; % hack to create slender tooth
angleOffPoints(12:16:end) = angleOffPoints(12:16:end) - 1/toothNumber^1.7; % hack to create slender tooth
radiusOffPoints( 1:16:end) = rootRadius; % center bottom I
radiusOffPoints( 2:16:end) = rootRadius; % left bottom I
radiusOffPoints( 3:16:end) = rootRadius; % left bottom corner +
radiusOffPoints( 4:16:end) = lowerRisingRadius; % lower rising bottom \
radiusOffPoints( 5:16:end) = effectiveRadius; % rising edge \
radiusOffPoints( 6:16:end) = upperRisingRadius; % upper rising edge \
radiusOffPoints( 7:16:end) = outsideRadius; % right top corner +
radiusOffPoints( 8:16:end) = outsideRadius; % right top I
radiusOffPoints( 9:16:end) = outsideRadius; % center top I
radiusOffPoints(10:16:end) = outsideRadius; % left top I
radiusOffPoints(11:16:end) = outsideRadius; % left top corner +
radiusOffPoints(12:16:end) = upperRisingRadius; % upper falling edge /
radiusOffPoints(13:16:end) = effectiveRadius; % falling edge /
radiusOffPoints(14:16:end) = lowerRisingRadius; % lower falling edge /
radiusOffPoints(15:16:end) = rootRadius; % right bottom corner +
radiusOffPoints(16:16:end) = rootRadius; % right bottom I
[X,Y] = pol2cart(angleOffPoints,radiusOffPoints);
[Xout,Yout] = poly2cw(Xout,Yout);
[X, Y ] = poly2cw(X ,Y );
[Xb,Yb] = polybool('subtraction',Xout,Yout, X,Y);
Xb = Xb(~isnan(Xb)); % notNaN
Yb = Yb(~isnan(Yb)); % notNaN
patch(Xb,Yb,colFilling,'EdgeColor','none')
plot(X, Y, 'linewidth',linW,'color',[0 0 0]); % draw teeth outline
plot(Xout,Yout,'linewidth',linW,'color',[0 0 0]); % draw outer circle
function map = struct2map(RGB)
% RGB: struct of depth 1 with [r g b] in each field
fNames = fieldnames(RGB);
nNames = numel(fNames);
map = NaN(nNames,3); % allocate
for iName = 1:nNames
map(iName,:) = RGB.(fNames{iName}); %
end
function im = imReduceSize(im,redSize)
% Input:
% im: image, [imRows x imColumns x nChannel x nStack] (unit8)
% imRows, imColumns: must be divisible by redSize
% nChannel: usually 3 (RGB) or 1 (grey)
% nStack: number of stacked images
% usually 1; >1 for animations
% redSize: 2 = half the size (quarter of pixels)
% 3 = third the size (ninth of pixels)
% ... and so on
% Output:
% imNew: unit8([imRows/redSize x imColumns/redSize x nChannel x nStack])
%
% an alternative is : imNew = imresize(im,1/reduceImage,'bilinear');
% BUT 'bicubic' & 'bilinear' produces fuzzy lines
% IMHO this function produces nicer results as "imresize"
[nRow,nCol,nChannel,nStack] = size(im);
if redSize==1; return; end % nothing to do
if redSize~=round(abs(redSize)); error('"redSize" must be a positive integer'); end
if rem(nRow,redSize)~=0; error('number of pixel-rows must be a multiple of "redSize"'); end
if rem(nCol,redSize)~=0; error('number of pixel-columns must be a multiple of "redSize"'); end
nRowNew = nRow/redSize;
nColNew = nCol/redSize;
im = double(im).^2; % brightness rescaling from "linear to the human eye" to the "physics domain"; see youtube: /watch?v=LKnqECcg6Gw
im = reshape(im, nRow, redSize, nColNew*nChannel*nStack); % packets of width redSize, as columns next to each other
im = sum(im,2); % sum in all rows. Size of result: [nRow, 1, nColNew*nChannel]
im = permute(im, [3,1,2,4]); % move singleton-dimension-2 to dimension-3; transpose image. Size of result: [nColNew*nChannel, nRow, 1]
im = reshape(im, nColNew*nChannel*nStack, redSize, nRowNew); % packets of width redSize, as columns next to each other
im = sum(im,2); % sum in all rows. Size of result: [nColNew*nChannel, 1, nRowNew]
im = permute(im, [3,1,2,4]); % move singleton-dimension-2 to dimension-3; transpose image back. Size of result: [nRowNew, nColNew*nChannel, 1]
im = reshape(im, nRowNew, nColNew, nChannel, nStack); % putting all channels (rgb) back behind each other in the third dimension
im = uint8(sqrt(im./redSize^2)); % mean; re-normalize brightness: "scale linear to the human eye"; back in uint8
function map = createImMap(imRGB,nCol,startMap)
% createImMap creates a color-map including predefined colors.
% "rgb2ind" creates a map but there is no option to predefine some colors,
% and it does not handle stacked images.
% Input:
% imRGB: image, [imRows x imColumns x 3(RGB) x nStack] (unit8)
% nCol: total number of colors the map should have, [integer]
% startMap: predefined colors; colormap format, [p x 3] (double)
imRGB = permute(imRGB,[1 2 4 3]); % step1; make unified column-image (handling possible nStack)
imRGBcolumn = reshape(imRGB,[],1,3,1); % step2; make unified column-image
fullMap = double(permute(imRGBcolumn,[1 3 2]))./255; % "column image" to color map
[fullMap,~,imMapColumn] = unique(fullMap,'rows'); % find all unique colores; create indexed colormap-image
% "cmunique" could be used but is buggy and inconvenient because the output changes between "uint8" and "double"
nColFul = size(fullMap,1);
nColStart = size(startMap,1);
disp(['Number of colors: ' num2str(nColFul) ' (including ' num2str(nColStart) ' self defined)']);
if nCol<=nColStart; error('Not enough colors'); end
if nCol>nColFul; warning('More colors than needed'); end
isPreDefCol = false(size(imMapColumn)); % init
for iCol = 1:nColStart
diff = sum(abs(fullMap-repmat(startMap(iCol,:),nColFul,1)),2); % difference between a predefined and all colores
[mDiff,index] = min(diff); % find matching (or most similar) color
if mDiff>0.05 % color handling is not precise
warning(['Predefined color ' num2str(iCol) ' does not appear in image'])
continue
end
isThisPreDefCol = imMapColumn==index; % find all pixel with predefined color
disp([num2str(sum(isThisPreDefCol(:))) ' pixel have predefined color ' num2str(iCol)]);
isPreDefCol = or(isPreDefCol,isThisPreDefCol); % combine with overall list
end
[~,mapAdditional] = rgb2ind(imRGBcolumn(~isPreDefCol,:,:),nCol-nColStart,'nodither'); % create map of remaining colors
map = [startMap;mapAdditional];
function RGB = roundToUINT8pos(RGB)
% Round rgb [0 to 1] to values that matches nicely to a uint8 compatible pos
% This not strictly necessary, but it makes later colormap-work less
% ambiguous and can help to avoid dithering of larger areas.
% Input / output: RGB: [r g b]
RGB = round( RGB.*255)./255; % round it to possible uint8 color
Licensing[edit]
![]() ![]() |
This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
|
![]() |
|
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 19:27, 14 October 2017 | ![]() | 600 × 500 (10.36 MB) | Jahobr (talk | contribs) | color pallet better |
19:05, 13 September 2017 | ![]() | 600 × 500 (11.53 MB) | Jahobr (talk | contribs) | GraphicsSmoothing with matlab 2017 | |
10:41, 20 June 2017 | ![]() | 600 × 500 (10.44 MB) | Jahobr (talk | contribs) | User created page with UploadWizard |
- You cannot overwrite this file.
File usage on Commons
The following 80 pages uses this file:
- User:Geoleplubo
- User:Jahobr
- User:Jahobr/Gearboxes
- User:Sophie Österberg (WMSE)/nyflip
- User:Spinster/Favorites
- User:Zhuyifei1999/sandbox/2
- User talk:Jahobr
- User talk:Laitche/Archive/2017
- Commons:Featured picture candidates/File:Unnecessarily complicated gears a.gif
- Commons:Featured picture candidates/Log/November 2017
- Commons:Featured pictures
- Commons:Featured pictures, list
- Commons:Featured pictures/Animated
- Commons:Featured pictures/af
- Commons:Featured pictures/als
- Commons:Featured pictures/an
- Commons:Featured pictures/ar
- Commons:Featured pictures/ast
- Commons:Featured pictures/be-tarask
- Commons:Featured pictures/bn
- Commons:Featured pictures/br
- Commons:Featured pictures/ca
- Commons:Featured pictures/chronological/2017-B
- Commons:Featured pictures/cs
- Commons:Featured pictures/da
- Commons:Featured pictures/de
- Commons:Featured pictures/el
- Commons:Featured pictures/eo
- Commons:Featured pictures/es
- Commons:Featured pictures/eu
- Commons:Featured pictures/ext
- Commons:Featured pictures/fi
- Commons:Featured pictures/fr
- Commons:Featured pictures/gl
- Commons:Featured pictures/gu
- Commons:Featured pictures/he
- Commons:Featured pictures/hr
- Commons:Featured pictures/hy
- Commons:Featured pictures/ia
- Commons:Featured pictures/id
- Commons:Featured pictures/it
- Commons:Featured pictures/ko
- Commons:Featured pictures/lb
- Commons:Featured pictures/mk
- Commons:Featured pictures/ml
- Commons:Featured pictures/mo
- Commons:Featured pictures/ms
- Commons:Featured pictures/nan
- Commons:Featured pictures/nl
- Commons:Featured pictures/no
- Commons:Featured pictures/oc
- Commons:Featured pictures/pl
- Commons:Featured pictures/pt
- Commons:Featured pictures/ro
- Commons:Featured pictures/ru
- Commons:Featured pictures/sk
- Commons:Featured pictures/sl
- Commons:Featured pictures/sq
- Commons:Featured pictures/su
- Commons:Featured pictures/sv
- Commons:Featured pictures/uk
- Commons:Featured pictures/vi
- Commons:Imatges de qualitat
- Commons:Mmàggini n vitrina
- Commons:Picture of the Year/2017/Candidates
- Commons:Picture of the Year/2017/R1/Gallery/2017-B
- Commons:Picture of the Year/2017/R1/Gallery/ALL
- Commons:Picture of the Year/2017/R1/Gallery/M11
- Commons:Picture of the Year/2017/R1/Gallery/Videos and Animations
- Commons:Picture of the Year/2017/R1/v/Unnecessarily complicated gears a.gif
- Commons:Quality images/Subject/Non photographic media
- Commons:Quality images candidates/Archives November 22 2017
- Commons:Seçilmiş şəkil
- Commons:Seçkin resimler/tr
- Commons:រូបភាពពិសេស/km
- Commons:正圖
- Commons:特色图片
- Commons:特色圖片
- Commons:特色靚相
- Commons:秀逸な画像
File usage on other wikis
The following other wikis use this file:
- Usage on en.wikipedia.org
- Usage on fa.wikipedia.org
- Usage on ko.wikipedia.org
- Usage on pcd.wikipedia.org
- Usage on pt.wikipedia.org
- Usage on ru.wikipedia.org