File:Ellipses with SliderCrank Ellipses at Crank Side.gif
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
Ellipses_with_SliderCrank_Ellipses_at_Crank_Side.gif (350 × 525 pixels, file size: 1.64 MB, MIME type: image/gif, looped, 220 frames, 8.8 s)
File information
Structured data
Captions
Summary
[edit]DescriptionEllipses with SliderCrank Ellipses at Crank Side.gif |
English: Two example ellipses are drawn in red and cyan. |
Date | |
Source | Own work |
Author | Jahobr |
Other versions |
|
GIF development InfoField | |
Source code InfoField | MATLAB codefunction Ellipses_with_SliderCrank()
% source code for drawing Tusi_couple_vs_Trammel
% produces a GIF and a SVG
%
% 2017-04-10 Jahobr
p = 1;
nFrames = 220;
angleSmall = linspace(0,2*pi,nFrames+1); % define gear position in frames
angleSmall = angleSmall(1:end-1); % remove last frame, it would be double
[pathstr,fname] = fileparts(which(mfilename)); % save files under the same name and at file location
figHandle = figure(15674455);
clf
axesHandle = axes;
hold(axesHandle,'on')
set(figHandle, 'Units','pixel');
for currentCase = 1:3
axis equal; drawnow;
for iFrame = 1:nFrames;
boxN = 0.1*p; % narrow side
boxL = 0.2*p; % long side
currentAngle = angleSmall(iFrame);
cla(axesHandle) % fresh frame
barCol = [0.5 0.5 0.5]; % color of bar
colHori = [0.1 0.7 0.1]; % green
switch currentCase
case 1 % outer ellipses slider side
set(figHandle, 'position',[1 1 700 1050]); % big start image for antialiasing later [x y width hight]
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]
xlim(p*[-1.3 1.3]);
ylim(p*[-2 2]);
% x slider x cnank side slider x cnank side
plot([p*cos(currentAngle) -0.7*p*cos(currentAngle)],[0 1.7*p*sin(currentAngle)],'.-','color',[0.5 0.5 0.5],'linewidth',35,'MarkerSize',100); % grey bar
rectangle(0,0,boxL+p*2,boxN,[0.8 0.8 0.8])
rectangle(p*cos(currentAngle),0,boxL,boxN,colHori)
case 2 % inner ellipses
set(figHandle, 'position',[1 1 1300 650 ]); % big start image for antialiasing later [x y width hight]
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]
xlim(p*[-1.25 1.25]);
ylim(p*[-0.625 0.625]);
plot([p*cos(currentAngle) p*cos(currentAngle)/2],[0 p*sin(currentAngle)/2],'.-','color',[0.5 0.5 0.5],'linewidth',35,'MarkerSize',100); % grey bar
rectangle(0,0,boxL/2+p*2,boxN/2,[0.8 0.8 0.8])
rectangle(p*cos(currentAngle),0,boxL/2,boxN/2,colHori)
case 3 % outer ellipses crank side
set(figHandle, 'position',[1 1 1300 600]); % big start image for antialiasing later [x y width hight]
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]
xlim(p*[-2 2]);
ylim(p*[-0.9 0.9]);
plot([1.7*p*cos(currentAngle) p*cos(currentAngle)/2],[-0.7*p*sin(currentAngle) p*sin(currentAngle)/2],'.-','color',[0.5 0.5 0.5],'linewidth',35,'MarkerSize',100); % grey bar
rectangle(0,0,boxL+p*2,boxN,[0.8 0.8 0.8])
rectangle(p*cos(currentAngle),0,boxL,boxN,colHori)
end
circle(0,0,p/2,':m'); % rot circle
plot(p*cos(currentAngle),0,'.','MarkerSize',30,'linewidth',4,'color',barCol) % overwrite line with trammel bar color
plot([p,-p],[0 0],':','MarkerSize',25,'linewidth',4,'color',colHori) % horizontal line
plot(p*cos(currentAngle),0,'.','MarkerSize',20,'linewidth',4,'color',colHori) % small dot to indicate the precise position
plot([0 p*cos(currentAngle)/2],[0 p*sin(currentAngle)/2],'-k','linewidth',5) % crank
plot(p*cos(currentAngle)/2,p*sin(currentAngle)/2,'.m','MarkerSize',40) % joint
plot(0, 0,'.k','MarkerSize',40) % touching point / Instant centre of rotation
col1 = [0 0.9 0.9]; % cyan
col2 = [1 0 0]; % red
switch currentCase
case 1 % outer ellipses crank side
ellOneOffset = 0.2;
ellTwoOffset = 0.7;
curVers = '_Ellipses_at_Crank_Side';
ellipse(0,0,ellOneOffset,p+ellOneOffset,col1,4);
plot(-ellOneOffset*cos(currentAngle),(p+ellOneOffset)*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col1);
ellipse(0,0,ellTwoOffset,p+ellTwoOffset,col2,4);
plot(-ellTwoOffset*cos(currentAngle),(p+ellTwoOffset)*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col2);
case 2 % inner ellipses
ellOneOffset = 0.4;
ellTwoOffset = 0.2;
curVers = '_inner_Ellipses';
ellipse(0,0,p/2+ellOneOffset,p/2-ellOneOffset,col1,4);
plot((p/2+ellOneOffset)*cos(currentAngle),(p/2-ellOneOffset)*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col1);
ellipse(0,0,p/2+ellTwoOffset,p/2-ellTwoOffset,col2,4);
plot((p/2+ellTwoOffset)*cos(currentAngle),(p/2-ellTwoOffset)*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col2);
case 3 % outer ellipses slider side
ellOneOffset = 0.2;
ellTwoOffset = 0.7;
curVers = '_Ellipses_at_Slider_Side';
ellipse(0,0,p+ellOneOffset,ellOneOffset,col1,4);
plot((p+ellOneOffset)*cos(currentAngle),-ellOneOffset*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col1);
ellipse(0,0,p+ellTwoOffset,ellTwoOffset,col2,4);
plot((p+ellTwoOffset)*cos(currentAngle),-ellTwoOffset*sin(currentAngle),'.','MarkerSize',40,'linewidth',3,'color',col2);
end
%% save animation
drawnow
pause(0.05)
if iFrame == 1 % create colormap
deleteMe = circle(0,0,p/2.5,'-k'); % rot circle
f = getframe(figHandle); % to get mix colores
f.cdata = imresize(f.cdata,0.5); % the size reduction: adds antialiasing
[im,map] = rgb2ind(f.cdata,32,'nodither'); % 32 colors % create color map %% THE FIRST FRAME MUST INCLUDE ALL COLORES !!!
% FIX WHITE, rgb2ind sets white to [0.9961 0.9961 0.9961], which is annoying
[~,wIndex] = max(sum(map,2)); % find "white"
map(wIndex,:) = 1; % make it truly white
im(1,1,1,nFrames) = 0; % allocate
delete(deleteMe); % delete colormap-line
end
f = getframe(figHandle);
f.cdata = imresize(f.cdata,0.5); % the size reduction: adds antialiasing
imtemp = rgb2ind(f.cdata,map,'nodither');
im(:,:,1,iFrame) = imtemp;
if iFrame == round(nFrames*0.20)
if ~isempty(which('plot2svg'))
plot2svg(fullfile(pathstr, [fname curVers '.svg']),figHandle) % by Juerg Schwizer
else
disp('plot2svg.m not available; see http://www.zhinst.com/blogs/schwizer/');
end
end
end
imwrite(im,map,fullfile(pathstr, [fname curVers '.gif']),'DelayTime',1/25,'LoopCount',inf) % save gif
disp([fname curVers '.gif has ' num2str(numel(im)/10^6 ,4) ' Megapixels']) % Category:Animated GIF files exceeding the 50 MP limit
end
return
%%
function h = circle(x,y,r,style)
% x coordinates of the center
% y coordinates of the center
% r is the radius of the circle
angleOffPoints = linspace(0,2*pi,300);
xc = x + r*cos(angleOffPoints);
yc = y + r*sin(angleOffPoints);
%plot(xc,yc,'k','linewidth',4);
h = plot(xc,yc,style,'linewidth',4);
function h = ellipse(x,y,a,b,col,linw)
% x coordinates of the center
% y coordinates of the center
% a radius1
% b radius2
angleOffPoints = linspace(0,2*pi,300);
xe = x + a*cos(angleOffPoints);
ye = y + b*sin(angleOffPoints);
h = plot(xe,ye,'-','linewidth',linw,'color',col);
function rectangle(x,y,width,height,col)
% x coordinates of the center
% y coordinates of the center
% width
% height
plot([x-width/2 x+width/2 x+width/2 x-width/2 x-width/2],[y-height/2 y-height/2 y+height/2 y+height/2 y-height/2],'-','linewidth',3,'color',col);
|
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
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.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
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:37, 30 May 2017 | 350 × 525 (1.64 MB) | Jahobr (talk | contribs) | more frames, minor fixes | |
22:50, 4 May 2017 | 350 × 525 (1.29 MB) | Jahobr (talk | contribs) | messed up names | ||
22:35, 4 May 2017 | 650 × 300 (1.19 MB) | Jahobr (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following 5 pages use this file:
File usage on other wikis
The following other wikis use this file:
- Usage on de.wikipedia.org