Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.
functionlever_in_balance()% source code that produces a GIF and a SVG%% 2017-11-01 JahobrrampUpDown=[0:0.1:1linspace(1,2,90)2:-0.2:0];% speed profilerampUpDown=cumsum(rampUpDown);% distancerampUpDown=rampUpDown(1:end-1);% remove redundant pointrampUpDown=rampUpDown./rampUpDown(end);% normalize (0 to 1)xPosList=[(0.5+rampUpDown./2)(1+rampUpDown(2:end))];% x position with intermediate stopnFrames=numel(xPosList);[pathstr,fname]=fileparts(which(mfilename));% save files under the same name and at file locationleverThickness=0.05;leverLength=[-1.12.1];leverOff=0.17;% lever offsetxH=0.3:0.01:2.3;% HyperbolayH=1./xH;% Hyperbola%% create figurefigHandle=figure(15677755);clfset(figHandle,'Units','pixel');set(figHandle,'GraphicsSmoothing','on')% requires at least version 2014baxesHandle=axes;hold(axesHandle,'on')versionList{1}='hyperbola';% full version with force vectors and hyperbolaversionList{2}='weights';% reduced; just lever and weightsforversionNr=1:numel(versionList)cla(axesHandle)% fresh framesaveName=[fname'_'versionList{versionNr}];RGB=struct;RGB.black=[000];RGB.white=[111];RGB.leverEdge=[0.550.270.08];% brownRGB.leverFace=[0.700.50.35];% brownRGB.weight=[0.60.60.6];% greyRGB.weight2=[0.70.70.7];% grey shineRGB.weight3=[0.80.80.8];% grey glareRGB.coordinate=[0.30.30.3];% greyifversionNr==1xSize=500;% size in pixelySize=450;% size in pixelscaleReduction=2;% the size reduction: adds antialiasingxLimits=[-1.422.38];yLimits=[-0.982.25];RGB.LForce=[000.8];% blueRGB.RForce=[100];% redRGB.LText=[000.3];% blueRGB.RText=[0.200];% redRGB.LArea=[0.70.71];% blueRGB.RArea=[10.70.7];% redRGB.Hyper=[10.70.7];% redelsexSize=900;% size in pixelySize=250;% size in pixelscaleReduction=2;% the size reduction: adds antialiasingxLimits=[-1.422.38];yLimits=[-0.950.1];endRGB=structfun(@(q)round(q*255)/255,RGB,'UniformOutput',false);% round to values that are nicely uint8 compatibleliSc=xSize*scaleReduction/1000;set(figHandle,'Position',[11[xSizeySize]*scaleReduction]);% big start image for antialiasing later [x y width height]set(axesHandle,'Position',[-0.05-0.051.11.1]);% stretch axis bigger as figure, easy way to get rid of ticks [x y width height]xlim(xLimits);ylim(yLimits);axisequal;drawnow;%% plot loopreducedRGBimage=uint8(ones(ySize,xSize,3,nFrames));% allocateforiFrame=1:nFramescla(axesHandle)% fresh framexPos=xPosList(iFrame);ifversionNr==1forceR=1/xPos;weightL=1000/9.81;%weightR=1000*forceR/9.81;%plotBox([-10],[01],RGB.LArea,'none',1)plotBox([0xPos],[01/xPos],RGB.RArea,'none',1)elseweightL=100;weightR=100/xPos;endplot(leverLength+0.05,[00],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% horizontal arrowplot(leverLength(2)+0.05+[-0.080-0.08],[-0.0200.02],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% Arrowheadplot(leverLength(2)+0.05+[-0.08-0.02-0.08],[-0.0200.02],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% ArrowheadplotBox(leverLength,[-leverThickness0]-leverOff,RGB.leverFace,RGB.leverEdge,2.5*liSc)% leverforscale=ceil(leverLength(1)):0.1:floor(leverLength(2))ifscale*2==round(scale*2)plot([scalescale],[-0.007-leverThickness+0.007]-leverOff,'Color',RGB.leverEdge,'LineWidth',5*liSc)% bar scaleplot([scalescale],[-0.02+0.02],'-','Color',RGB.coordinate,'LineWidth',5*liSc)% coordinate scaletext(scale,-0.01,num2str(scale),...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.coordinate,'FontUnits','pixel','FontSize',33*liSc,...'HorizontalAlignment','center','VerticalAlignment','top');elseplot([scalescale],[-0.009-leverThickness+0.009]-leverOff,'Color',RGB.leverEdge,'LineWidth',2.5*liSc)% bar scaleplot([scalescale],[-0.015+0.015],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% coordinate scaleendendifversionNr==1text(2.03,0.03,'[m]',...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.coordinate,'FontUnits','pixel','FontSize',33*liSc,...'HorizontalAlignment','left','VerticalAlignment','bottom');plot(xH,yH,':','Color',[10.10.1],'LineWidth',7*liSc)% Hyperbolaplot([00],[02.15],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% vertical arrowplot([-0.0200.02],[2.072.152.07],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% Arrowheadplot([-0.0200.02],[2.072.132.07],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% Arrowheadforscale=0:0.1:2.0ifscale*2==round(scale*2)plot([-0.02+0.02],[scalescale],'-','Color',RGB.coordinate,'LineWidth',5*liSc)% coordinate scaleifscale>0text(-0.03,scale,num2str(scale,'%3.1f'),...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.coordinate,'FontUnits','pixel','FontSize',33*liSc,...'HorizontalAlignment','right','VerticalAlignment','middle');endelseplot([-0.015+0.015],[scalescale],'-','Color',RGB.coordinate,'LineWidth',2.5*liSc)% coordinate scaleendendtext(-0.05,2.12,'F [kN]',...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.coordinate,'FontUnits','pixel','FontSize',33*liSc,...'HorizontalAlignment','right','VerticalAlignment','middle');text(-0.5,1,'1.00 m',...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.LText,'FontUnits','pixel','FontSize',45*liSc,...'HorizontalAlignment','center','VerticalAlignment','cap');text(-0.98,0.1,'1.00 kN',...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.LText,'FontUnits','pixel','FontSize',45*liSc,...'HorizontalAlignment','left','VerticalAlignment','bottom');text(-0.5,0.46,'$${\bf M_L}$$',...'interpreter','Latex',...'Color',RGB.LText,'FontUnits','pixel','FontSize',70*liSc,...'HorizontalAlignment','center','VerticalAlignment','middle');plot([-1-1],[0.041],'-','Color',RGB.LForce,'LineWidth',5.0*liSc)plot([-0.0200.02]-1,[0.090.010.09],'-','Color',RGB.LForce,'LineWidth',2.5*liSc)% Arrowheadplot([-0.0200.02]-1,[0.090.040.09],'-','Color',RGB.LForce,'LineWidth',2.5*liSc)% Arrowheadtext(xPos/2,forceR,[num2str(xPos,'%1.2f')' m'],...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.RText,'FontUnits','pixel','FontSize',45*liSc,...'HorizontalAlignment','center','VerticalAlignment','cap');text(xPos-0.02,0.1,[num2str(forceR,'%1.2f')' kN'],...'FontWeight','bold','FontName','Helvetica Narrow',...'Color',RGB.RText,'FontUnits','pixel','FontSize',45*liSc,...'HorizontalAlignment','right','VerticalAlignment','bottom');text(xPos/2,forceR*0.46,'$${\bf M_R}$$',...'interpreter','Latex',...'Color',RGB.RText,'FontUnits','pixel','FontSize',70*liSc,...'HorizontalAlignment','center','VerticalAlignment','middle');plot([xPosxPos],[0.04forceR],'-','Color',RGB.RForce,'LineWidth',5.0*liSc)plot([-0.0200.02]+xPos,[0.090.010.09],'-','Color',RGB.RForce,'LineWidth',2.5*liSc)% Arrowheadplot([-0.0200.02]+xPos,[0.090.040.09],'-','Color',RGB.RForce,'LineWidth',2.5*liSc)% Arrowheadtext(2.15,2,'$${\bf M_L+M_R =0}$$',...'interpreter','Latex',...'FontUnits','pixel','FontSize',70*liSc,...'HorizontalAlignment','right','VerticalAlignment','middle');text(0.95,1.7,'$${\bf M_L}$$',...'interpreter','Latex',...'FontUnits','pixel','FontSize',50*liSc,...'HorizontalAlignment','left','VerticalAlignment','middle');text(2.15,1.7,'$${\bf =+1\,kNm}$$',...'interpreter','Latex',...'FontUnits','pixel','FontSize',50*liSc,...'HorizontalAlignment','right','VerticalAlignment','middle');text(0.95,1.5,'$${\bf M_R}$$',...'interpreter','Latex',...'FontUnits','pixel','FontSize',50*liSc,...'HorizontalAlignment','left','VerticalAlignment','middle');text(2.15,1.5,'$${\bf =-1\,kNm}$$',...'interpreter','Latex',...'FontUnits','pixel','FontSize',50*liSc,...'HorizontalAlignment','right','VerticalAlignment','middle');endbearing(0,-leverThickness-leverOff,0.3)disc(0,-leverThickness-leverOff,0.02,RGB.white,RGB.black,2.5*liSc)plotWeight(-1,-leverOff,weightL)plotWeight(xPos,-leverOff,weightR)%% save animationxlim(xLimits);ylim(yLimits);drawnow;% set axis limitsf=getframe(figHandle);reducedRGBimage(:,:,:,iFrame)=imReduceSize(f.cdata,scaleReduction);% the size reduction: adds antialiasingifany(xPos==[0.512])% SVGdisp(['x='num2str(xPos)' at Frame 'num2str(iFrame)]);if~isempty(which('plot2svg'))plot2svg(fullfile(pathstr,[saveName'_1-'num2str(xPos)'.svg']),figHandle)% by Juerg Schwizerelsedisp('plot2svg.m not available; see http://www.zhinst.com/blogs/schwizer/');endendendstartMap=cell2mat(struct2cell(RGB));% struct2colormap; % list of map colors that are not allowed to be changedmap=createImMap(reducedRGBimage,32,startMap);% colormapim=uint8(ones(ySize,xSize,1,nFrames));% allocateforiFrame=1:nFramesim(:,:,1,iFrame)=rgb2ind(reducedRGBimage(:,:,:,iFrame),map,'nodither');endimwrite(im,map,fullfile(pathstr,[saveName'.gif']),'DelayTime',1/25,'LoopCount',inf)% save gifdisp([saveName'.gif has 'num2str(numel(im)/10^6,4)' Megapixels'])% Category:Animated GIF files exceeding the 50 MP limitendfunctionplotWeight(x,y,weight)% x [left right]% y [top bottom]% force in kNle=0.11;% ropeLengthdensity=2500;% adjust% V = weight/density = 4/3*pi*r^3r=nthroot((weight*3)/(density*4*pi),3);% radiusdisc(x,y-le-r/6,r/3,RGB.weight,RGB.black,2.5*liSc)% handle (material)disc(x,y-le-r/6,r/6,RGB.white,RGB.black,2.5*liSc)% handle (hole)disc(x,y-le-r*1.25,r,RGB.weight,RGB.black,2.5*liSc)% bodydisc(x-r*0.4,y-le-r*0.75,r/3,RGB.weight2,'none',1)% shinedisc(x-r*0.45,y-le-r*0.7,r/5,RGB.weight3,'none',1)% glaretext(x,y-le-r*1.05,num2str(weight,'%5.1f'),...'FontWeight','bold','FontName','Helvetica',...'Color',RGB.black,'FontUnits','pixel','FontSize',200*r*liSc,...'HorizontalAlignment','center','VerticalAlignment','middle');text(x,y-le-r*1.65,'kg',...'FontWeight','bold','FontName','Helvetica',...'Color',RGB.black,'FontUnits','pixel','FontSize',200*r*liSc,...'HorizontalAlignment','center','VerticalAlignment','middle');plot([xx],y+[0.03-le-0.03],'Color',RGB.black,'LineWidth',6*liSc);endfunctionbearing(x,y,sizze)% x coordinates of the center% y coordinates of the center% sizeplot([0-0.50.50]*sizze+x,[0-0.8660-0.86600]*sizze+y,'k','LineWidth',5*liSc,'Color',RGB.black);% Triangle % 0.8660 = sqrt(3)*0.5plot([-0.70.7]*sizze+x,[-0.87-0.87]*sizze+y,'k','LineWidth',5*liSc,'Color',RGB.black);% base lineforiLine=-0.6:0.2:0.7plot(([-0.10.1]+iLine)*sizze+x,[-1.07-0.87]*sizze+y,'k','LineWidth',3*liSc,'Color',RGB.black);% Hatchingendendendfunctiondisc(x,y,r,colFa,colEd,linWi)% x coordinates of the center% y coordinates of the center% r is the radius of the circle% colFa FaceColor% colEd EdgeColor% linWi LineWidthangleOffPoints=linspace(0,2*pi,300);xc=x+r*sin(angleOffPoints);yc=y+r*cos(angleOffPoints);patch(xc,yc,'k','LineWidth',linWi,'EdgeColor',colEd,'FaceColor',colFa);% ,'FaceAlpha',0.2% transparencc does onl work in 'renderer','OpenGL' but that fails in combination with "getframe"endfunctionplotBox(x,y,colFa,colEd,linw)% x [left right]% y [top bottom]% colFa face color [r g b]% colEd edge color [r g b]% linw line widthxs=[x(1)x(1)x(2)x(2)x(1)x(1)];% xys=[mean(y)y(1)y(1)y(2)y(2)mean(y)];% y joint in the middle of an edge to get nice cornerspatch(xs,ys,colFa,'EdgeColor',colEd,'LineWidth',linw);%endfunctionim=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:% im: [imRows/redSize x imColumns/redSize x nChannel x nStack] (unit8)%% 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);ifredSize==1;return;end% nothing to doifredSize~=round(abs(redSize));error('"redSize" must be a positive integer');endifrem(nRow,redSize)~=0;error('number of pixel-rows must be a multiple of "redSize"');endifrem(nCol,redSize)~=0;error('number of pixel-columns must be a multiple of "redSize"');endnRowNew=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=LKnqECcg6Gwim=reshape(im,nRow,redSize,nColNew*nChannel*nStack);% packets of width redSize, as columns next to each otherim=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 otherim=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 dimensionim=uint8(sqrt(im./redSize^2));% mean; re-normalize brightness: "scale linear to the human eye"; back in uint8endfunctionmap=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,[1243]);% step1; make unified column-image (handling possible nStack)imRGBcolumn=reshape(imRGB,[],1,3,1);% step2; make unified column-imagefullMap=double(permute(imRGBcolumn,[132]))./255;% "column image" to color map [fullMap,~,imMapColumn]=unique(fullMap,'rows');% find all unique colors; 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)']);ifnCol<=nColStart;error('Not enough colors');endifnCol>nColFul;warning('More colors than needed');endisPreDefCol=false(size(imMapColumn));% initforiCol=1:nColStartdiff=sum(abs(fullMap-repmat(startMap(iCol,:),nColFul,1)),2);% difference between a predefined and all colors[mDiff,index]=min(diff);% find matching (or most similar) colorifmDiff>0.05% color handling is not precisewarning(['Predefined color 'num2str(iCol)' does not appear in image'])continueendisThisPreDefCol=imMapColumn==index;% find all pixel with predefined colordisp([num2str(sum(isThisPreDefCol(:)))' pixel have predefined color 'num2str(iCol)]);isPreDefCol=or(isPreDefCol,isThisPreDefCol);% combine with overall listend[~,mapAdditional]=rgb2ind(imRGBcolumn(~isPreDefCol,:,:),nCol-nColStart,'nodither');% create map of remaining colorsmap=[startMap;mapAdditional];end
Lizenz
Ich, der Urheber dieses Werkes, veröffentliche es unter der folgenden Lizenz:
Die Person, die das Werk mit diesem Dokument verbunden hat, übergibt dieses weltweit der Gemeinfreiheit, indem sie alle Urheberrechte und damit verbundenen weiteren Rechte – im Rahmen der jeweils geltenden gesetzlichen Bestimmungen – aufgibt. Das Werk kann – selbst für kommerzielle Zwecke – kopiert, modifiziert und weiterverteilt werden, ohne hierfür um Erlaubnis bitten zu müssen.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse
Kurzbeschreibungen
Ergänze eine einzeilige Erklärung, was diese Datei darstellt.