/
Asymptote:TheVectorGraphicsLanguageJohnBowmanandAndyHammerlindlDepartm Asymptote:TheVectorGraphicsLanguageJohnBowmanandAndyHammerlindlDepartm

Asymptote:TheVectorGraphicsLanguageJohnBowmanandAndyHammerlindlDepartm - PDF document

karlyn-bohler
karlyn-bohler . @karlyn-bohler
Follow
362 views
Uploaded On 2016-05-11

Asymptote:TheVectorGraphicsLanguageJohnBowmanandAndyHammerlindlDepartm - PPT Presentation

History1979TEXandMETAFONTKnuth19862DBeziercontrolpointselectionHobby1989MetaPostHobby2004Asymptote2004initialpublicreleaseHammerlindlBowmanPrince20053DBeziercontrolpointselect ID: 315725

History1979:TEXandMETAFONT(Knuth)1986:2DBeziercontrolpointselection(Hobby)1989:MetaPost(Hobby)2004:Asymptote{2004:initialpublicrelease(Hammerlindl Bowman &Prince){2005:3DBeziercontrolpointselect

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Asymptote:TheVectorGraphicsLanguageJohnB..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Asymptote:TheVectorGraphicsLanguageJohnBowmanandAndyHammerlindlDepartmentofMathematicalandStatisticalSciencesUniversityofAlbertaCollaborators:OrestShardt,MichailVidiassovJune30,2010http://asymptote.sf.net/intro.pdf1 Historyˆ1979:TEXandMETAFONT(Knuth)ˆ1986:2DBeziercontrolpointselection(Hobby)ˆ1989:MetaPost(Hobby)ˆ2004:Asymptote{2004:initialpublicrelease(Hammerlindl,Bowman,&Prince){2005:3DBeziercontrolpointselection(Bowman){2008:3DinteractiveTEXwithinPDF les(Shardt&Bowman){2009:3Dbillboardlabelsthatalwaysfacecamera(Bowman){2010:3DPDFenhancements(Vidiassov&Bowman)2 Statistics(asofJune,2010)ˆRunsunderLinux/UNIX,MacOSX,MicrosoftWindows.ˆ4000downloads/monthfromprimaryasymptote.sourceforge.netsitealone.ˆ80000linesoflow-levelC++code.ˆ36000linesofhigh-levelAsymptotecode.3 VectorGraphicsˆRastergraphicsassigncolorstoagridofpixels. ˆVectorgraphicsaregraphicswhichstillmaintaintheirlookwheninspectedatarbitrarilysmallscales. 4 CartesianCoordinatesˆAsymptote'sgraphicalcapabilitiesarebasedonfourprimitivecommands:draw,label,fill,clip[BH08]draw((0,0)--(100,100)); ˆunitsarePostScriptbigpoints(1bp=1/72inch)ˆ--meansjointhepointswithalinearsegmenttocreateapathˆcyclicpath:draw((0,0)--(100,0)--(100,100)--(0,100)--cycle); 5 ScalingtoaGivenSizeˆPostScriptunitsareofteninconvenient.ˆInstead,scaleusercoordinatestoaspeci ed nalsize:size(3cm);draw((0,0)--(1,0)--(1,1)--(0,1)--cycle); ˆOnecanalsospecifythesizeincm:size(3cm,3cm);draw(unitsquare); 6 LabelsˆAddingandaligningLATEXlabelsiseasy:size(6cm);draw(unitsquare);label("$A$",(0,0),SW);label("$B$",(1,0),SE);label("$C$",(1,1),NE);label("$D$",(0,1),NW); 7 2DBezierSplinesˆUsing..insteadof--speci esaBeziercubicspline:draw(z0..controlsc0andc1..z1,blue); (1�t)3z0+3t(1�t)2c0+3t2(1�t)c1+t3z1;t2[0;1]:8 SmoothPathsˆAsymptotecanchoosecontrolpointsforyou,usingthealgorithmsofHobbyandKnuth[Hob86,Knu86]:pair[]z=f(0,0),(0,1),(2,1),(2,0),(1,0)g;draw(z[0]..z[1]..z[2]..z[3]..z[4]..cycle,grey+linewidth(5));dot(z,linewidth(7)); ˆFirst,linearequationsinvolvingthecurvaturearesolvedto ndthedirectionthrougheachknot.Then,controlpointsalongthosedirectionsarechosen: 9 FillingˆThefillprimitiveto lltheinsideofapath:pathstar;for(inti=0;i5;++i)star=star--dir(90+144i);star=star--cycle;fill(star,orange+zerowinding);draw(star,linewidth(3));fill(shift(2,0)*star,blue+evenodd);draw(shift(2,0)*star,linewidth(3)); 10 FillingˆUsealistofpathsto llaregionwithholes:path[]p=fscale(2)*unitcircle,reverse(unitcircle)g;fill(p,green+zerowinding); 11 ClippingˆPicturescanbeclippedtoapath:fill(star,orange+zerowinding);clip(scale(0.7)*unitcircle);draw(scale(0.7)*unitcircle); 12 AneTransformsˆAnetransformations:shifts,rotations,re ections,andscalingscanbeappliedtopairs,paths,pens,strings,andevenwholepictures:fill(P,blue);fill(shift(2,0)*reflect((0,0),(0,1))*P,red);fill(shift(4,0)*rotate(30)*P,yellow);fill(shift(6,0)*yscale(0.7)*xscale(2)*P,green); 13 C++/Java-likeProgrammingSyntax//Declaration:Declarextobereal:realx;//Assignment:Assignxthevalue1.x=1.0;//Conditional:Testifxequals1ornot.if(x==1.0)fwrite("xequals1.0");gelsefwrite("xisnotequalto1.0");g//Loop:iterate10timesfor(inti=0;i10;++i)fwrite(i);g14 ModulesˆTherearemodulesforFeynmandiagrams, datastructures, 15 algebraicknottheory: (x1;x2;x3;x4;x5)=4b(x1+x4;x2;x3;x5)+4b(x1;x2;x3;x4)+4a(x1;x2+x3;x4;x5)�4b(x1;x2;x3;x4+x5)�4a(x1+x2;x3;x4;x5)�4a(x1;x2;x4;x5):16 TextbookGraphimportgraph;size(150,0);realf(realx)freturnexp(x);gpairF(realx)freturn(x,f(x));gxaxis("$x$");yaxis("$y$",0);draw(graph(f,-4,2,operator..),red);labely(1,E);label("$e^x$",F(1),SE); 17 Scienti cGraphimportgraph;size(250,200,IgnoreAspect);realSin(realt)freturnsin(2pi*t);grealCos(realt)freturncos(2pi*t);gdraw(graph(Sin,0,1),red,"$nsin(2npix)$");draw(graph(Cos,0,1),blue,"$ncos(2npix)$");xaxis("$x$",BottomTop,LeftTicks);yaxis("$y$",LeftRight,RightTicks(trailingzero));label("LABEL",point(0),UnFill(1mm));attach(legend(),truepoint(E),20E,UnFill);18 19 DataGraphimportgraph;size(200,150,IgnoreAspect);real[]x=f0,1,2,3g;real[]y=x^2;draw(graph(x,y),red);xaxis("$x$",BottomTop,LeftTicks);yaxis("$y$",LeftRight,RightTicks(Label(fontsize(8pt)),newreal[]f0,4,9g));20 21 ImportedDataGraphimportgraph;size(200,150,IgnoreAspect);filein=input("filegraph.dat").line();real[][]a=in;a=transpose(a);real[]x=a[0];real[]y=a[1];draw(graph(x,y),red);xaxis("$x$",BottomTop,LeftTicks);yaxis("$y$",LeftRight,RightTicks);22 23 LogarithmicGraphimportgraph;size(200,200,IgnoreAspect);realf(realt)freturn1/t;gscale(Log,Log);draw(graph(f,0.1,10));//limits((1,0.1),(10,0.5),Crop);dot(Label("(3,5)",align=S),Scale((3,5)));xaxis("$x$",BottomTop,LeftTicks);yaxis("$y$",LeftRight,RightTicks);24 25 SecondaryAxis 26 ImagesandContours 27 MultipleGraphs 28 Hobby's2DDirectionAlgorithmˆAtridiagonalsystemoflinearequationsissolvedtodetermineanyunspeci eddirectionskandkthrougheachknotzk:k�1�2k `k=k+1�2k `k+1: ˆTheresultingshapemaybeadjustedbymodifyingoptionaltensionparametersandcurlboundaryconditions.29 Hobby's2DControlPointAlgorithmˆHavingprescribedoutgoingandincomingpathdirectionseiatnodez0andeiatnodez1relativetothevectorz1�z0,thecontrolpointsaredeterminedas:u=z0+ei(z1�z0)f(;�);v=z1�ei(z1�z0)f(�;);wheretherelativedistancefunctionf(;)isgivenbyHobby[1986]. 30 BezierCurvesin3DˆApplyananetransformationx0i=Aijxj+CitoaBeziercurve:x(t)=3Xk=0Bk(t)Pk;t2[0;1]:ˆTheresultingcurveisalsoaBeziercurve:x0i(t)=3Xk=0Bk(t)Aij(Pk)j+Ci=3Xk=0Bk(t)P0k;whereP0kisthetransformedkthcontrolpoint,noting3Xk=0Bk(t)=1:31 3DGeneralizationofDirectionAlgorithmˆMustreduceto2Dalgorithminplanarcase.ˆDeterminedirectionsbyapplyingHobby'salgorithmintheplanecontainingzk�1,zk,zk+1.ˆTheonlyambiguitythatcanariseistheoverallsignoftheangles,whichrelatestoviewingeach2Dplanefromopposingnormaldirections.ˆAreferencevectorbasedonthemeanunitnormalofsuccessivesegmentscanbeusedtoresolvesuchambiguities[Bow07,BS09]32 3DControlPointAlgorithmˆExpressHobby'salgorithmintermsoftheabsolutedirections!0and!1:u=z0+!0jz1�z0jf(;�);v=z1�!1jz1�z0jf(�;); interpretingandastheanglebetweenthecorrespondingpathdirectionvectorandz1�z0.33 ˆHerethereisanunambiguousreferencevectorfordeterminingtherelativesignoftheanglesand.34 Interactive3DSaddleˆAunitcircleintheX{Yplanemaybeconstructedwith:(1,0,0)..(0,1,0)..(-1,0,0)..(0,-1,0)..cycle: andthendistortedintothesaddle(1,0,0)..(0,1,1)..(-1,0,0)..(0,-1,1)..cycle: 35 LiftingTeXto3DˆGlyphsare rstsplitintosimplyconnectedregionsandthendecomposedintoplanarBeziersurfacepatches[BS09,SB12]: 36 LabelManipulationˆTheycanthenbeextrudedand/orarbitrarilytransformed: 37 BillboardLabels 38 Smooth3Dsurfaces 39 Curved3DArrows 40 SlidePresentationsˆAsymptotehasamoduleforpreparingslides.ˆItevensupportsembeddedhigh-resolutionPDFmovies.title("SlidePresentations");item("Asymptotehasamoduleforpreparingslides.");item("Itevensupportsembeddedhigh-resolutionPDFmovies.");...41 AutomaticSizingˆFigurescanbespeci edinusercoordinates,thenautomaticallyscaledtothedesired nalsize. 42 DeferredDrawingˆWecan'tdrawagraphicalobjectuntilweknowthescalingfactorsfortheusercoordinates.ˆInstead,storeafunctionthat,giventhescalinginformation,drawsthescaledobject.voiddraw(picturepic=currentpicture,pathg,penp=currentpen)fpic.add(newvoid(framef,transformt)fdraw(f,t*g,p);g);pic.addPoint(min(g),min(p));pic.addPoint(max(g),max(p));g43 CoordinatesˆStoreboundingboxinformationasthesumofuserandtrue-sizecoordinates: pic.addPoint(min(g),min(p));pic.addPoint(max(g),max(p));ˆFillingignoresthepenwidth:pic.addPoint(min(g),(0,0));pic.addPoint(max(g),(0,0));ˆCommunicatewithLATEXviaapipetodeterminelabelsizes: 44 SizingˆWhenscalingthe nal guretoagivensizeS,we rstneedtodetermineascalingfactora�0andashiftbsothatallofthecoordinateswhentransformedwilllieintheinterval[0;S].ˆThatis,ifuandtaretheuserandtruesizecomponents:0au+t+bS:ˆMaximizethevariableasubjecttoanumberofinequalities.ˆUsethesimplexmethodtosolvetheresultinglinearprogrammingproblem.45 SizingˆEveryadditionofacoordinate(t;u)addstworestrictionsau+t+b0;au+t+bS;andeachdrawingcomponentaddstwocoordinates.ˆA gurecouldeasilyproducethousandsofrestrictions,makingthesimplexmethodimpractical.ˆMostoftheserestrictionsareredundant,however.Forinstance,withconcentriccircles,onlythelargestcircleneedstobeaccountedfor. 46 RedundantRestrictionsˆIngeneral,ifuu0andtt0thenau+t+bau0+t0+bforallchoicesofa�0andb,so0au+t+bau0+t0+bS:ˆThisde nesapartialorderingoncoordinates.Whensizingapicture,theprogram rstcomputeswhichcoordinatesaremaximal(orminimal)andonlysendse ectiveconstraintstothesimplexalgorithm.ˆInpractice,thelinearprogrammingproblemwillhavelessthanadozenrestraints.ˆAllpicturesizingisimplementedinAsymptotecode.47 In niteLinesˆDeferreddrawingallowsustodrawin nitelines.drawline(P,Q); 48 HelpfulMathNotationˆIntegerdivisionreturnsareal.Usequotientforanintegerresult:3/4==0.75quotient(3,4)==0ˆCaretforrealandintegerexponentiation:2^32.7^32.7^3.2ˆManyexpressionscanbeimplicitlyscaledbyanumericconstant:2pi10cm2x^23sin(x)2(a+b)ˆPairsarecomplexnumbers:(0,1)*(0,1)==(-1,0)49 FunctionCallsˆFunctionscantakedefaultargumentsinanyposition.Argumentsarematchedtothe rstpossiblelocation:voiddrawEllipse(realxsize=1,realysize=xsize,penp=blue)fdraw(xscale(xsize)*yscale(ysize)*unitcircle,p);gdrawEllipse(2);drawEllipse(red); ˆArgumentscanbegivenbyname:drawEllipse(xsize=2,ysize=1);drawEllipse(ysize=2,xsize=3,green); 50 RestArgumentsˆRestargumentsallowonetowriteafunctionthattakesanarbitrarynumberofarguments:intsum(...int[]nums)finttotal=0;for(inti=0;inums.length;++i)total+=nums[i];returntotal;gsum(1,2,3,4);//returns10sum();//returns0sum(1,2,3...newint[]f4,5,6g);//returns21intsubtract(intstart...int[]subs)freturnstart-sum(...subs);g51 High-OrderFunctionsˆFunctionsare rst-classvalues.Theycanbepassedtootherfunctions:importgraph;realf(realx)freturnx*sin(10x);gdraw(graph(f,-3,3,300),red); 52 Higher-OrderFunctionsˆFunctionscanreturnfunctions:fn(x)=nsinx n:typedefrealfunc(real);funcf(intn)frealfn(realx)freturnn*sin(x/n);greturnfn;gfuncf1=f(1);realy=f1(pi);for(inti=1;i=5;++i)draw(graph(f(i),-10,10),red); 53 AnonymousFunctionsˆCreatenewfunctionswithnew:pathp=graph(newreal(realx)freturnx*sin(10x);g,-3,3,red);funcf(intn)freturnnewreal(realx)freturnn*sin(x/n);g;gˆFunctionde nitionsarejustsyntacticsugarforassigningfunctionobjectstovariables.realsquare(realx)freturnx^2;gisequivalenttorealsquare(realx);square=newreal(realx)freturnx^2;g;54 StructuresˆAsinotherlanguages,structuresgrouptogetherdata.structPersonfstringfirstname,lastname;intage;gPersonbob=newPerson;bob.firstname="Bob";bob.lastname="Chesterton";bob.age=24;ˆAnycodeinthestructurebodywillbeexecutedeverytimeanewstructureisallocated...structPersonfwrite("Makingaperson.");stringfirstname,lastname;intage=18;gPersoneve=newPerson;//Writes"Makingaperson."write(eve.age);//Writes18.55 ModulesˆFunctionandstructurede nitionscanbegroupedintomodules://powers.asyrealsquare(realx)freturnx^2;grealcube(realx)freturnx^3;gandimported:importpowers;realeight=cube(2.0);draw(graph(powers.square,-1,1));56 Object-OrientedProgrammingˆFunctionsarede nedforeachinstanceofastructure.structQuadraticfreala,b,c;realdiscriminant()freturnb^2-4*a*c;grealeval(realx)freturna*x^2+b*x+c;ggˆThisallowsustoconstruct\methods"whicharejustnormalfunctionsdeclaredintheenvironmentofaparticularobject:Quadraticpoly=newQuadratic;poly.a=-1;poly.b=1;poly.c=2;realf(realx)=poly.eval;realy=f(2);draw(graph(poly.eval,-5,5));57 SpecializationˆCancreatespecializedobjectsjustbyrede ningmethods:structShapefvoiddraw();realarea();gShaperectangle(realw,realh)fShapes=newShape;s.draw=newvoid()ffill((0,0)--(w,0)--(w,h)--(0,h)--cycle);g;s.area=newreal()freturnw*h;g;returns;gShapecircle(realradius)fShapes=newShape;s.draw=newvoid()ffill(scale(radius)*unitcircle);g;s.area=newreal()freturnpi*radius^2;greturns;g58 OverloadingˆConsiderthecode:intx1=2;intx2()freturn7;gintx3(inty)freturn2y;gwrite(x1+x2());//Writes9.write(x3(x1)+x2());//Writes11.59 Overloadingˆx1,x2,andx3areneverusedinthesamecontext,sotheycanallberenamedxwithoutambiguity:intx=2;intx()freturn7;gintx(inty)freturn2y;gwrite(x+x());//Writes9.write(x(x)+x());//Writes11.ˆFunctionde nitionsarejustvariablede nitions,butvariablesaredistinguishedbytheirsignaturestoallowoverloading.60 OperatorsˆOperatorsarejustsyntacticsugarforfunctions,andcanbeaddressedorde nedasfunctionswiththeoperatorkeyword.intadd(intx,inty)=operator+;write(add(2,3));//Writes5.//Don'ttrythisathome.intoperator+(intx,inty)freturnadd(2x,y);gwrite(2+3);//Writes7.ˆThisallowsoperatorstobede nedfornewtypes.61 OperatorsˆOperatorsforconstructingpathsarealsofunctions:a..controlsbandc..d--eisequivalenttooperator--(operator..(a,operatorcontrols(b,c),d),e)ˆThisallowedustorede neallofthepathoperatorsfor3Dpaths.62 SummaryˆAsymptote:{usesIEEE oatingpointnumerics;{usesC++/Java-likesyntax;{supportsdeferreddrawingforautomaticpicturesizing;{supportsGrayscale,RGB,CMYK,andHSVcolourspaces;{supportsPostScriptshading,pattern lls,andfunctionshading;{can llnonsimplyconnectedregions;{generalizesMetaPostpathconstructionalgorithmsto3D;{liftsTEXto3D;{supports3DbillboardlabelsandPDFgrouping.63 References[BH08]JohnC.BowmanandAndyHammerlindl.Asymptote:Avectorgraphicslanguage.TUGboat:TheCommunicationsoftheTEXUsersGroup,29(2):288{294,2008.[Bow07]JohnC.Bowman.The3DAsymptotegeneralizationofMetaPostBezierinterpolation.ProceedingsinAppliedMathematicsandMechanics,7(1):2010021{2010022,2007.[BS09]JohnC.BowmanandOrestShardt.Asymptote:LiftingTEXtothreedimensions.TUGboat:TheCommunicationsoftheTEXUsersGroup,30(1):58{63,2009.[Hob86]JohnD.Hobby.Smooth,easytocomputeinterpolatingsplines.DiscreteComput.Geom.,1:123{140,1986.[Knu86]DonaldE.Knuth.TheMETAFONTbook.Addison-Wesley,Reading,Massachusetts,1986.[SB12]OrestShardtandJohnC.Bowman.SurfaceparametrizationofnonsimplyconnectedplanarBezierregions.Computer-AidedDesign,44(5):484.e1{10,2012. Asymptote:2D&3DVectorGraphicsLanguage http://asymptote.sf.net(freelyavailableundertheLGPLlicense)64