File:Asymmetric Epicyclic Gearing Stationary Sun.gif

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Asymmetric_Epicyclic_Gearing_Stationary_Sun.gif(335 × 335 pixels, file size: 2.85 MB, MIME type: image/gif, looped, 450 frames, 18 s)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
Deutsch: Unsymmetrisches Umlaufrädergetriebe; Zähne: zSonne=22, zPlanet_1=14, zPlanet_1=26, zPlanet_1=38, zHohl=74.
English: Eccentric Planetary Gears. Asymmetric epicyclic gearing; Teeth: zsun=22, zplanet_1=14, zplanet_2=26, zplanet_3=38, zring=74.
Date
Source Own work
Author Jahobr
Other versions
GIF development
InfoField
Matlab Logo 
This diagram was created with MATLAB by Jahobr.
Source code
InfoField

MATLAB code

function Asymmetric_Epicyclic_Gearing()
% Source code for drawing epicyclic gearing.
% The shape of the gears is not precise, it creates a decent GIF and a SVG.
%
% 2017-06-21 Jahobr

teethSun  = 22;
teethPlan = [14 26 38];
teethRing = 74;

modul = 16;

carrierCol = round([0.1  0.7  0.1].*255)./255; % green
sunCol     = round([0.95 0.65 0  ].*255)./255; % yellow (obviously)
palnetCol  = round([0.2  0.2  1  ].*255)./255; % blue   (obviously)
ringCol    = round([1    0.2  0.2].*255)./255; % red

xySize = 335; % size in pixel
scaleReduction = 3; % the size reduction: adds antialiasing

diameterPlan = modul.*teethPlan;
diameterRing = modul.*teethRing;

[pathstr,fname] = fileparts(which(mfilename)); % save files under the same name and at file location

figHandle = figure(15674455); clf
set(figHandle,'Units','pixel');
set(figHandle,'ToolBar','none');
set(figHandle,'GraphicsSmoothing','on') % requires at least version 2014b
set(figHandle,'position',[1 1 [xySize xySize]*scaleReduction]); % big start image for antialiasing later [x y width height]
axesHandle = axes;
hold(axesHandle,'on')
set(axesHandle,'position',[-0.05 -0.05 1.1 1.1]); % stretch axis bigger as figure, easy way to get rid of ticks [x y width height]
axis equal; drawnow;

% Rotation offsets to align teeth
angleOffsetRing = pi/teethRing; % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleOffsetSun=0.1972;          % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleOffsetPlan(1)=0;           % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleOffsetPlan(2)=0.043;       % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT
angleOffsetPlan(3)=0.094;       % ALLIGNMENT; THIS MAY NEED MANUAL ADJUSTMENT


% polar coordinates of gears
radSun  = 224.4037; % found by try and error
angSun = 0.4078;    % found by try and error

radPlan = (diameterRing-diameterPlan)./2; %
angPlan(1) = 0;
angPlan(2) = pi*2/3-0.415; % 1/3 of a circle , but not quite (found by try and error)
angPlan(3) = pi*4/3+0.075; % 2/3 of a circle , but not quite (found by try and error)

for currentCase = 1:4; %
    xlim([-diameterRing diameterRing]*0.72); % default
    ylim([-diameterRing diameterRing]*0.72); % default
    switch currentCase
        case {1,2} % Stationary & Nonrotating Sun
            nFrames = 450;
            reducedRGBimage = uint8(ones(xySize,xySize,3,nFrames)); % allocate
            angleCarrier = -linspace(0,pi*2,nFrames+1); % define gear position in frames
            angleCarrier = angleCarrier(1:end-1); % remove last frame, it would be double

            anglePlan = (( teethSun./teethPlan)'+1) *angleCarrier; % gear ratio
            anglePlan = anglePlan + angleOffsetPlan(:)*ones(size(angleCarrier)); % 

            angleRing = angleCarrier.*  (teethSun+teethRing) / teethRing; % gear ratio
            angleRing = angleRing + angleOffsetRing; 

            angleSun = zeros(size(anglePlan))+angleOffsetSun;
            if currentCase == 1
                saveName = [fname '_Stationary_Sun'];
                xlim([-diameterRing diameterRing]*0.95); % bigger range
                ylim([-diameterRing diameterRing]*0.95); % bigger range
            elseif currentCase == 2
                saveName = [fname '_Nonrotating_Sun'];
            end

        case 3 % Stationary_Ring
            nFrames = 450;
            reducedRGBimage = uint8(ones(xySize,xySize,3,nFrames)); % allocate
            angleCarrier = -linspace(0,pi*2,nFrames+1); % define gear position in frames
            angleCarrier = angleCarrier(1:end-1); % remove last frame, it would be double

            anglePlan = (( teethRing./teethPlan)'-1)*angleCarrier; % gear ratio 
            anglePlan = -anglePlan + angleOffsetPlan(:)*ones(size(angleCarrier)); % 

            angleSun = angleCarrier.*  (1+teethRing/teethSun); % gear ratio
            angleSun = angleSun + angleOffsetSun; % 
            
            angleRing = zeros(size(anglePlan)) + angleOffsetRing; % 
            
            saveName = [fname '_Stationary_Ring'];

        case 4 % Stationary_Carrier
            nFrames = 20;
            reducedRGBimage = uint8(ones(xySize,xySize,3,nFrames)); % allocate
            angleSun = -linspace(0,pi*2/teethSun,nFrames+1); % define gear position in frames
            angleSun = angleSun(1:end-1); % remove last frame, it would be double

            angleRing = -angleSun.*  (teethSun/teethRing); % gear ratio
            angleRing =  angleRing + angleOffsetRing; % 

            anglePlan =  ((teethSun./teethPlan )')*angleSun; % gear ratio
            anglePlan = -anglePlan + angleOffsetPlan(:)*ones(size(angleSun)); % 

            angleCarrier = zeros(size(anglePlan));
            
            angleSun = angleSun + angleOffsetSun; % 

            saveName = [fname '_Stationary_Carrier'];
    end

    for iFrame = 1:nFrames

        cla(axesHandle) % fresh frame

        %% ring
        drawRingGear(teethRing,modul,ringCol,angleRing(iFrame))

        %% sun
        [X,Y] = pol2cart(angSun+angleCarrier(iFrame),radSun);
        drawCogWheel([X,Y],teethSun ,modul,sunCol,angleSun(iFrame));
        
        if currentCase == 1 % viewbox shift for "_Stationary_Sun"; improvised, but it works
            xlim([-diameterRing diameterRing]*0.92+X); % bigger range
            ylim([-diameterRing diameterRing]*0.92+Y); % bigger range
        end

        %% planets
        for iPlan = 1:numel(angPlan)
            [X,Y] = pol2cart(angPlan(iPlan)+angleCarrier(iFrame) ,radPlan(iPlan));
            drawCogWheel([X,Y],teethPlan(iPlan),modul,palnetCol,anglePlan(iPlan,iFrame)); % planetary gear
        end

        %% carrier
        % the carrier is adapted to the gears, to avoid obstruction of the sun gear
        
        %                                     % two extra nodes                                       one extra node                 
        angCarr = [angPlan(1)  (angPlan(1:2)*[2;1])/3 (angPlan(1:2)*[1;2])/3 angPlan(2)  angPlan(3) mean(angPlan([1,3])+[0 2*pi]) angPlan(1)];
        radCarr = [radPlan(1)  (radPlan(1:2)*[2;1])/3 (radPlan(1:2)*[1;2])/3 radPlan(2)  radPlan(3) mean(radPlan([1,3])+[0 2*pi]) radPlan(1)];
        
        angCarr(2) = angCarr(2)/1.4; % manual shift to avoid obstruction
        radCarr(2) = radCarr(2)*1.1; % manual shift to avoid obstruction
        
        angCarr(3) = angCarr(3)/1.3; % manual shift to avoid obstruction
        radCarr(3) = radCarr(3)*1.1; % manual shift to avoid obstruction
        
        angCarr(end-1) = angCarr(end-1)*1.12; % manual shift to avoid obstruction
        radCarr(end-1) = radCarr(end-1)/1.05; % manual shift to avoid obstruction

        [X,Y] = pol2cart(angCarr+angleCarrier(iFrame) ,radCarr);
        plot(X,Y,'color',[0 0 0],'LineWidth',33) % black outline
        plot(X,Y,'color',carrierCol,'LineWidth',30) % carrierCol "filling"
        
        for iPlan = 1:numel(angPlan)
            [X,Y] = pol2cart(angPlan(iPlan)+angleCarrier(iFrame) ,radPlan(iPlan));
            circlePatch(X,Y,diameterPlan(iPlan)*0.25,carrierCol,1.5);
            circlePatch(X,Y,diameterPlan(iPlan)*0.15,palnetCol,1.5);
        end
        
        %% save animation
        f = getframe(figHandle);
        reducedRGBimage(:,:,:,iFrame) = imReduceSize(f.cdata,scaleReduction); % the size reduction: adds antialiasing
        
        if iFrame == 1 % SVG
            if ~isempty(which('plot2svg'))
                plot2svg(fullfile(pathstr, [fname '_Stationary.svg']),figHandle) % by Juerg Schwizer
            else
                disp('plot2svg.m not available; see http://www.zhinst.com/blogs/schwizer/');
            end
        end
        
    end
    
    map = createImMap(reducedRGBimage,16,[0 0 0;1 1 1;carrierCol;sunCol;palnetCol;ringCol]); % colormap
    
    im = uint8(ones(xySize,xySize,1,nFrames)); % allocate
    for iFrame = 1:nFrames
        im(:,:,1,iFrame) = rgb2ind(reducedRGBimage(:,:,:,iFrame),map,'nodither');
    end
    
    imwrite(im,map,fullfile(pathstr, [saveName '.gif']),'DelayTime',1/25,'LoopCount',inf) % save gif
    disp([saveName '.gif  has ' num2str(numel(im)/10^6 ,4) ' Megapixels']) % Category:Animated GIF files exceeding the 50 MP limit
end
%%

function drawCogWheel(center,toothNumber,modul,colFilling,startOffset)
% DRAWTOOTHEDWHEEL - draw a simple Toothed Wheel
%
%  Input:
%    axesHandle:
%    center:       [x y]
%    toothNumber:  scalar
%    modul:        scalar tooth "size"
%    colFilling:   color of filling [r g b]
%    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

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 = 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
patch(X,Y,colFilling,'EdgeColor',[0 0 0],'LineWidth',1.5)
% plot(axesHandle,X,Y,'-x','linewidth',2,'color',[0 0 0]);

% %% effective Radius
% [X,Y] = pol2cart(angleOffPoints,effectiveRadius);
% X = X+center(1); % center offset
% Y = Y+center(2); % center offset
% plot(axesHandle,X,Y,'-.','color',[0 0 0]);


function drawRingGear(toothNumber,modul,colFilling,startOffset)
% subfunction for the outer static gear
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
[X,Y] = pol2cart(angleOffPoints,maxRadius);

patch(X,Y,colFilling,'EdgeColor',[0 0 0],'LineWidth',1.5) % full outer disc
% plot(axesHandle,X,Y,'linewidth',2,'color',[0 0 0]); % draw outer circle

%% 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);

patch(X,Y,[1 1 1],'EdgeColor',[0 0 0],'LineWidth',1.5) % overlay white area for inner teeth
% plot(axesHandle,X,Y,'-','linewidth',2,'color',[0 0 0]); % teeth line

function 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.001*pi,200);
xc = x + r*cos(angleOffPoints);
yc = y + r*sin(angleOffPoints);
patch(xc,yc,col,'EdgeColor',[0 0 0],'LineWidth',linW);

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];

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero 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 their 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/TimeThumbnailDimensionsUserComment
current22:41, 29 October 2017Thumbnail for version as of 22:41, 29 October 2017335 × 335 (2.85 MB)Jahobr (talk | contribs)graph smoothing
20:35, 24 June 2017Thumbnail for version as of 20:35, 24 June 2017334 × 334 (2.89 MB)Jahobr (talk | contribs)more fitting to the name
15:28, 21 June 2017Thumbnail for version as of 15:28, 21 June 2017334 × 334 (3.74 MB)Jahobr (talk | contribs)User created page with UploadWizard