Difference between revisions of "User:Azjps/geogebra"
m (→Statistics) |
(→Functions and Integrals) |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | '''Gallery of examples''': The following Asymptote codes were all generated from Geogebra files (File > Export > Graphics View as Asymptote ...). | + | '''Gallery of examples''': The following [[Asymptote (Vector Graphics Language)|Asymptote]] codes were all generated from [[Geogebra]] files (File > Export > Graphics View as Asymptote ...). It is available in the current release of the Geogebra 4.0 Beta version. To download Geogebra 4.0, go [http://www.geogebra.org/forum/viewtopic.php?f=22&t=1387 here] and either choose the webstart (direct) version or choose one of the 3.9 version offline installers (as beta versions, there may unfixed bugs, although the versions are for the most part stable.) |
+ | |||
+ | == Documentation == | ||
+ | Here is a fairly simple example that breaks down the contents of the output code, with Fill type set at "By layering". | ||
+ | |||
+ | <asy> | ||
+ | /* Geogebra to Asymptote conversion, documentation at userscripts.org/scripts/show/72997 */ | ||
+ | import graph; size(14.26cm); | ||
+ | real labelscalefactor = 0.5; /* changes label-to-point distance */ | ||
+ | pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ | ||
+ | pen dotstyle = black; /* point style */ | ||
+ | real xmin = -6.22,xmax = 8.04,ymin = -4.18,ymax = 4.76; /* image dimensions */ | ||
+ | pen fueaev = rgb(0.96,0.92,0.9); pen zzttqq = rgb(0.6,0.2,0); | ||
+ | |||
+ | real f2 (real x) {return sin(x);} | ||
+ | filldraw(graph(f2,0,pi )--(pi ,0)--(0,0)--cycle, fueaev, zzttqq); | ||
+ | filldraw((-3.14,0)--(0,0)--(0,3.14)--(-3.14,pi )--cycle, fueaev, zzttqq); | ||
+ | Label laxis; laxis.p = fontsize(10); string xaxislabel (real x) {int n=round(x/pi); if(n==-1) return "$-\pi$"; if(n==1) return "$\pi$"; if(n==0) return "$0$"; return "$" + string(n) + "\pi$";} string yaxislabel (real x) {return "$" + string(x) + "\,\mathrm{}$";} | ||
+ | xaxis("$x$",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); | ||
+ | yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true); | ||
+ | /* draw figures */ | ||
+ | real f1 (real x) {return sin(x);} | ||
+ | draw(graph(f1,-6.21,8.03)); | ||
+ | draw((-3.14,0)--(0,0), zzttqq); | ||
+ | draw((0,0)--(0,3.14), zzttqq); | ||
+ | draw((0,3.14)--(-3.14,pi ), zzttqq); | ||
+ | draw((-3.14,pi )--(-3.14,0), zzttqq); | ||
+ | draw(circle((0,3.14),1.14)); draw(shift((3.35,2.06))*rotate(1)*xscale(1.59)*yscale(1.1)*unitcircle); | ||
+ | pair hyperbolaLeft1 (real t) {return (0.49*(1+t^2)/(1-t^2),1.04*2*t/(1-t^2));} pair hyperbolaRight1 (real t) {return (0.49*(-1-t^2)/(1-t^2),1.04*(-2)*t/(1-t^2));} | ||
+ | draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaLeft1,-0.99,0.99)); draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaRight1,-0.99,0.99)); /* hyperbola construction */ | ||
+ | /* dots and labels */ | ||
+ | label("$f$",(-6.12,-0.12),NE * labelscalefactor); | ||
+ | label("$a = 2$",(1.46,0.24),NE * labelscalefactor,zzttqq); | ||
+ | dot((-3.14,0),dotstyle); | ||
+ | label("$A$",(-3.06,0.12),NE * labelscalefactor); | ||
+ | dot((2.2,2.04),dotstyle); | ||
+ | dot((4.5,2.08),dotstyle); | ||
+ | clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); | ||
+ | /* end of picture */ | ||
+ | </asy> | ||
+ | |||
+ | Here is the Asymptote code produced: (with some spacing added) | ||
+ | |||
+ | <pre> | ||
+ | /* Geogebra to Asymptote conversion, documentation at userscripts.org/scripts/show/72997 */ | ||
+ | import graph; size(14.26cm); | ||
+ | real labelscalefactor = 0.5; /* changes label-to-point distance */ | ||
+ | pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ | ||
+ | pen dotstyle = black; /* point style */ | ||
+ | real xmin = -6.22,xmax = 8.04,ymin = -4.18,ymax = 4.76; /* image dimensions */ | ||
+ | pen fueaev = rgb(0.96,0.92,0.9); pen zzttqq = rgb(0.6,0.2,0); | ||
+ | |||
+ | real f2 (real x) {return sin(x);} | ||
+ | filldraw(graph(f2,0,pi )--(pi ,0)--(0,0)--cycle, fueaev, zzttqq); | ||
+ | filldraw((-3.14,0)--(0,0)--(0,3.14)--(-3.14,pi )--cycle, fueaev, zzttqq); | ||
+ | Label laxis; laxis.p = fontsize(10); | ||
+ | string xaxislabel (real x) { | ||
+ | int n=round(x/pi); | ||
+ | if(n==-1) return "<math>-\pi</math>"; | ||
+ | if(n==1) return "<math>\pi</math>"; | ||
+ | if(n==0) return "<math>0</math>"; | ||
+ | return "<math>" + string(n) + "\pi</math>";} | ||
+ | string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";} | ||
+ | xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); | ||
+ | yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true); | ||
+ | |||
+ | /* draw figures */ | ||
+ | real f1 (real x) {return sin(x);} | ||
+ | draw(graph(f1,-6.21,8.03)); | ||
+ | draw((-3.14,0)--(0,0), zzttqq); | ||
+ | draw((0,0)--(0,3.14), zzttqq); | ||
+ | draw((0,3.14)--(-3.14,pi ), zzttqq); | ||
+ | draw((-3.14,pi )--(-3.14,0), zzttqq); | ||
+ | draw(circle((0,3.14),1.14)); draw(shift((3.35,2.06))*rotate(1)*xscale(1.59)*yscale(1.1)*unitcircle); | ||
+ | pair hyperbolaLeft1 (real t) {return (0.49*(1+t^2)/(1-t^2),1.04*2*t/(1-t^2));} | ||
+ | pair hyperbolaRight1 (real t) {return (0.49*(-1-t^2)/(1-t^2),1.04*(-2)*t/(1-t^2));} | ||
+ | draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaLeft1,-0.99,0.99)); | ||
+ | draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaRight1,-0.99,0.99)); /* hyperbola construction */ | ||
+ | |||
+ | /* dots and labels */ | ||
+ | label("<math>f</math>",(-6.12,-0.12),NE * labelscalefactor); | ||
+ | label("<math>a = 2</math>",(1.46,0.24),NE * labelscalefactor,zzttqq); | ||
+ | dot((-3.14,0),dotstyle); | ||
+ | label("<math>A</math>",(-3.06,0.12),NE * labelscalefactor); | ||
+ | dot((2.2,2.04),dotstyle); | ||
+ | dot((4.5,2.08),dotstyle); | ||
+ | clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); | ||
+ | /* end of picture */ | ||
+ | </pre> | ||
+ | |||
+ | Here is a line-by-line explanation: (<math>\texttt{/* COMMENT */}</math> are comments that are not read by the Asymptote engine.) | ||
+ | |||
+ | <math>\texttt{import graph; size(14.26cm); }</math> are the opening commands: any files that need to be imported (in this case, [http://asymptote.sourceforge.net/doc/graph.html graph]), followed by the horizontal size in centimeters, as shown by the Export to Asymptote window. | ||
+ | |||
+ | <math>\texttt{real labelscalefactor = 0.5; /* changes label-to-point distance */}</math> This variable scales the distance that labels are from their defined locations on the Geogebra window. This is due to an innate difference in the Asymptote and Geogebra treatment of labels: Geogebra positions labels with respect to a corner of the label, but Asymptote positions labels with respect to the center. Also, both have different default font sizes. The larger the value of <math>\texttt{labelscalefactor}</math>, the farther the Asymptote labels are dislocated from their respective points. Usually, <math>\texttt{labelscalefactor}</math> will have to be lowered to better position the labels (truer for longer labels). In concise mode, this variable is abbreviated as <math>\texttt{lsf}</math>. | ||
+ | |||
+ | <pre> | ||
+ | pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ | ||
+ | pen dotstyle = black; /* point style */ | ||
+ | </pre> | ||
+ | |||
+ | These are the definition of the default pens to use. <math>\texttt{dps}</math> stands for default pen style and produces the default pen style. <math>\texttt{dotstyle}</math> stands for the default dot style. In concise mode, the latter is abbreviated as <math>\texttt{ds}</math>, and in cse5, this option is completely replaced by the pen <math>\texttt{pointpen}</math>. | ||
+ | |||
+ | <code>real xmin = -6.22,xmax = 8.04,ymin = -4.18,ymax = 4.76; /* image dimensions */ }</code> | ||
+ | |||
+ | As the comment suggests, these four variables define the boundaries of the picture (in the units of the picture). Rays and lines that go out of the picture are defined in terms of these variables, as well as the clip window. Thus, changing these variables should keep intact most of the Asymptote contents. | ||
+ | |||
+ | <code> | ||
+ | pen fueaev = rgb(0.96,0.92,0.9); pen zzttqq = rgb(0.6,0.2,0); | ||
+ | </code> | ||
+ | |||
+ | These pens are custom defined colors, which are actually defined by hexadecimal values of the associated colors. The colors can be changed in this line (changing a specific shade to a darker shade, for example). | ||
+ | |||
+ | <code> | ||
+ | filldraw((-3.14,0)--(0,0)--(0,3.14)--(-3.14,pi )--cycle, fueaev, zzttqq); | ||
+ | </code> | ||
+ | |||
+ | This <math>\texttt{filldraw}</math> command draws a square in the picture. Of note is that if the axes are defined in terms of pi, then some coordinates are defined in terms of the Asymptote variable <math>\texttt{pi}</math>. The command changes to <math>\texttt{draw}</math> if the Fill type is set to "None". | ||
+ | |||
+ | <pre> | ||
+ | real f2 (real x) {return sin(x);} | ||
+ | filldraw(graph(f2,0,pi )--(pi ,0)--(0,0)--cycle, fueaev, zzttqq); | ||
+ | </pre> | ||
+ | |||
+ | Some commands have to be defined with respect to a function. <math>\texttt{f2}</math> returns the <math>\sin(x)</math> function, and the <math>\texttt{graph}</math> command draws <math>\texttt{f2}</math> from <math>x = 0</math> to <math>x = \pi</math>. | ||
+ | |||
+ | <pre> | ||
+ | Label laxis; laxis.p = fontsize(10); | ||
+ | string xaxislabel (real x) { | ||
+ | int n=round(x/pi); | ||
+ | if(n==-1) return "<math>-\pi</math>"; | ||
+ | if(n==1) return "<math>\pi</math>"; | ||
+ | if(n==0) return "<math>0</math>"; | ||
+ | return "<math>" + string(n) + "\pi</math>";} | ||
+ | string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";} | ||
+ | xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); | ||
+ | yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true); | ||
+ | </pre> | ||
+ | |||
+ | These commands draw the axes. The <math>\texttt{laxis}</math> label specifies the label styles of the axes (e.g., the field <math>\texttt{laxis.p}</math> defines the desired font pen). | ||
+ | |||
+ | The next line, the <pre>string xaxislabel (real x) { | ||
+ | int n=round(x/pi); | ||
+ | if(n==-1) return "<math>-\pi</math>"; | ||
+ | if(n==1) return "<math>\pi</math>"; | ||
+ | if(n==0) return "<math>0</math>"; | ||
+ | return "<math>" + string(n) + "\pi</math>";} | ||
+ | string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";} </pre> are functions that define the labels for both axes. These are abbreviated as <math>\texttt{xlbl, ylbl}</math> in the concise mode. The first defines axes with labels with respect to <math>\pi</math>, and it formats the labels so that the <math>0</math> label simply outputs <math>0</math> instead of <math>0\pi</math>, and <math> \pm \pi</math> instead of <math> \pm 1\pi</math>. Finally, | ||
+ | |||
+ | <pre> | ||
+ | xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); | ||
+ | yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true); | ||
+ | </pre> | ||
+ | |||
+ | are the commands that actually construct the xaxis and the yaxis. For documentation, see [http://asymptote.sourceforge.net/doc/graph.html here]. | ||
+ | |||
+ | The next block of code does the actual construction of the geometric figures. <pre> | ||
+ | /* draw figures */ | ||
+ | real f1 (real x) {return sin(x);} | ||
+ | draw(graph(f1,-6.21,8.03)); | ||
+ | draw((-3.14,0)--(0,0), zzttqq); | ||
+ | draw((0,0)--(0,3.14), zzttqq); | ||
+ | draw((0,3.14)--(-3.14,pi ), zzttqq); | ||
+ | draw((-3.14,pi )--(-3.14,0), zzttqq); | ||
+ | draw(circle((0,3.14),1.14)); draw(shift((3.35,2.06))*rotate(1)*xscale(1.59)*yscale(1.1)*unitcircle); | ||
+ | pair hyperbolaLeft1 (real t) {return (0.49*(1+t^2)/(1-t^2),1.04*2*t/(1-t^2));} pair hyperbolaRight1 (real t) {return (0.49*(-1-t^2)/(1-t^2),1.04*(-2)*t/(1-t^2));} | ||
+ | draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaLeft1,-0.99,0.99)); draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaRight1,-0.99,0.99)); /* hyperbola construction */ </pre> The first line <tt>real f1 (real x) {return sin(x);} </tt> defines the <tt>sin()</tt> function to be drawn, and the next line <tt>draw(graph(f1,-6.21,8.03)); </tt> actually draws the graph to the diagram. The <tt>graph()</tt> command comes from the Asymptote <tt>graph</tt> [http://asymptote.sourceforge.net/doc/graph.html package]. The next few lines draw several line segments. The attribute <tt>zzttqq</tt> is a pen whose color is mapped from some rgb value (with conversions <tt>... 8 = y, 9 = z, a = a, b = b, ... </tt>). | ||
+ | |||
+ | == Options == | ||
+ | An outline of the different available options. | ||
+ | |||
+ | (The first three options are related and automatically update with respect to eath other). | ||
+ | |||
+ | '''X/Y Units (cm)''': Indicates how many units in the picture correspond to 1 centimeter. | ||
+ | |||
+ | '''Picture width/height''': Indicates what size the Asymptote output should be, in centimeters. | ||
+ | |||
+ | '''xmin/xmax/ymin/ymax''': Indicates the dimensions of the picture in the picture's coordinates. | ||
+ | |||
+ | (The next options change other features). | ||
+ | |||
+ | '''Font size''': Changes the default font size. The value defaults at 10pt, but I personally recommend 7pt for any file with multiple text lines, which more closely approximates the size of the font in the Geogebra window. | ||
+ | |||
+ | '''Fill type''': This includes four options as to how Geogebra elements with different fill colors should be implemented: | ||
+ | |||
+ | * None: No fills are drawn. | ||
+ | * Only opaque fills. This will only cause filled objects with opaque transparencies, which are arbitrarily defined as shapes with transparency alpha values greater than 0.9 (on a 0 to 1, 1 being fully opaque, scale), to appear filled. | ||
+ | * With opacity pen. This uses the opacity() pen to draw transparency fills. This option does not work on the AoPS forums. | ||
+ | * By layering (my personal preference). Filled objects have "fake transparency" where filled objects are simply drawn before any other objects are drawn, and transparencies just cause a lighter shade. However, filled objects will override other filled objects, and so there is no "darker" transparencies along intersecting regions. | ||
+ | |||
+ | '''Concise code''': This produces shorter Asymptote code. Some of the changes between non-concise and concise code: | ||
+ | |||
+ | * In non-concise code, most new commands have their own line. In concise code, there are at most about 8 lines of code. | ||
+ | * Abbreviations are used for certain variables (labelscalefactor to lsf, xaxislabel to xlbl, gridx to gx, and so forth). | ||
+ | * Pen colors are produced with a single line of pen declarations. | ||
+ | * Functions are re-used where possible. | ||
+ | * Less spacing. | ||
+ | |||
+ | The advantages of concise code: | ||
+ | |||
+ | * Less code to examine. | ||
+ | * Non-concise code will usually not render on the AoPS forums due to size limits. | ||
+ | * Guide to customizing code should be in the following posts. | ||
+ | |||
+ | The disadvantages of concise code: | ||
+ | |||
+ | * More difficult to read (especially without experience with my style of coding), exacerbated by lack of spacing. | ||
+ | * No documentation comments. | ||
+ | * Difficult to read through from given code window, requires wrap-around to read effectively. | ||
+ | |||
+ | '''Concise with cse5''': There is also a cse5 option that allows the code to be further compactified with help with the cse5 package (see the stickies in this forum). | ||
+ | |||
+ | * In non-concise code, most new commands have their own line. In cse5 code, there are at most about 8 lines of code. | ||
+ | * Abbreviations are used for certain variables (labelscalefactor to lsf, xaxislabel to xlbl, gridx to gx, and so forth). | ||
+ | * Pairs are given names and produced in a single line; color pens are also produced in a single line. | ||
+ | * Functions are re-used where possible. | ||
+ | * Command shortcuts, such as MP() and D() are used extensively. | ||
+ | * Almost no spacing. | ||
+ | |||
+ | The advantages of cse5 code: | ||
+ | |||
+ | * Less code to examine. | ||
+ | * With the exception of excessively complicated diagrams, will almost always fit within AoPS size restrictions. | ||
+ | * Guide to customizing code should be in the following posts. | ||
+ | * Allows more customization; changing a declared point and pen will reflect changes across the code. | ||
+ | |||
+ | The disadvantages of cse5 code: | ||
+ | |||
+ | * Extremely difficult to read (especially without experience with my style of coding), exacerbated by lack of spacing and short commands. | ||
+ | * No documentation comments. | ||
+ | * Difficult to read through from given code window, requires wrap-around to read effectively. | ||
+ | * May occasionally draw skinny points and lines, due to default pathpen and pointpen attributes. | ||
+ | |||
+ | My personal recommendation is the concise code for producing quick sketches (cse5 for large quick sketches), and the non-concise code otherwise. | ||
+ | |||
+ | '''Grayscale''': Uses monochromatic scale to produce all output. | ||
+ | |||
+ | '''Show Axes/Grid''' (default checked): Show or hide the axes and the grid. | ||
+ | |||
+ | '''Keep dot colors''': Geogebra defaults free points to a blue color and semi-fixed points to a light blue color. Without this option checked, the Asymptote code will automatically set points to the default color (black). With checked, the Asymptote code will include the point colors as shown in the Geogebra window. | ||
+ | |||
+ | '''Use point names''': (to do) In the Asymptote code, store points in <math>\texttt{pair}</math> variables rather than by write out by coordinates. Done by default for concise cse5 code. | ||
== Points == | == Points == | ||
Line 30: | Line 271: | ||
* Labels may be displaced more from points than shown in Geogebra window. This is not really a bug but a font problem, since Asymptote will write the labels in LaTeX, which has a different size from normal text. The recommended solution is to decrease the font size to fontsize(8) or fontsize(7). | * Labels may be displaced more from points than shown in Geogebra window. This is not really a bug but a font problem, since Asymptote will write the labels in LaTeX, which has a different size from normal text. The recommended solution is to decrease the font size to fontsize(8) or fontsize(7). | ||
− | * In cse5 mode, certain dots will appear smaller (default pointpen nature of cse5, not fixing). | + | * Leaving <b>Keep Dot Colors()</b> unchecked will color as black any labels which are a single character long and set to the default shade of blue for new points (presumably all such labels will be dot labels, which is the desired behavior). |
+ | * Some of the point styles might not be perfectly accurate when zoomed in. | ||
+ | * In cse5 mode, certain dots will appear smaller (default pointpen nature of cse5, not fixing). | ||
+ | === Axes === | ||
+ | There is support for drawing the x and y axes of the diagram (indeed, without <b>Show Axes/Grid</b> unchecked, and assuming the axes are visible in the Geogebra window, then the axes will be drawn). However, there are several bugs: | ||
+ | * The Asymptote code will remove the tick labels for <math>0</math>. One can undo this by removing the attribute <tt>NoZero</tt> for the <tt>xaxis(), yaxis()</tt> commands. The reason is that the zero labels are not positioned well in Asymptote (indeed, the Geogebra tick labels for <math>0</math>, or whatever the intersection point is, are shifted slightly) | ||
+ | * The location where the label of the axes (typically "x" or "y") will by default appear in the first quadrant ("x" above the x-axis, "y" to the right of the y-axis). In Asymptote, the labels appear in the exact opposite locations ("x" below the x-axis, "y" to the left of the y-axis). Low priority bug which is unlikely to be fixed. | ||
+ | * There is no (easy) support in Asymptote for having the x or y axes intersect at any point other than the origin. In GeoGebra, one can use the <b>Crossing at</b> textbox under Properties to change where the x-axis and y-axis intersects. | ||
+ | * Geogebra recognizes near-multiples of <math>\pi</math> in axis tick distances; for example, if you enter an axis tick distance of <math>\pi/3 \approx 1.047\ldots</math>, Geogebra automatically renders it as <math>\pi</math> instead of <math>3.14\ldots</math>. There's no easy way to do it in Asymptote (if you do want to try and mimic the behavior, manually add a labelling function which checks to see if tick labels are sufficient close to an integer multiple of <math>\pi</math>. The code is too long to be worth included in general). Also, while <math>\pi/2</math> labels are implemented, <math>\pi/4</math> labels are soon to be introduced and have not been implemented. | ||
== Functions and Integrals == | == Functions and Integrals == | ||
Line 41: | Line 290: | ||
xaxis("$\theta$",-7.3,8.06,linewidth(1.2),Ticks(laxis,xlbl,Step=3.141592653589793,Size=2),Arrows(6),above=true); yaxis(-1.44,5.2,linewidth(1.2),Ticks(laxis,Step=1.0,Size=2),Arrows(6),above=true); real f1(real x){return 2+2*cos(2*x+pi);} draw(graph(f1,-7.29,8.05),linewidth(1.6)+ttqqzz); label("$2 + 2 \cos(2x + \pi)$",(-7.14,4.1),NE*lsf,ttqqzz); | xaxis("$\theta$",-7.3,8.06,linewidth(1.2),Ticks(laxis,xlbl,Step=3.141592653589793,Size=2),Arrows(6),above=true); yaxis(-1.44,5.2,linewidth(1.2),Ticks(laxis,Step=1.0,Size=2),Arrows(6),above=true); real f1(real x){return 2+2*cos(2*x+pi);} draw(graph(f1,-7.29,8.05),linewidth(1.6)+ttqqzz); label("$2 + 2 \cos(2x + \pi)$",(-7.14,4.1),NE*lsf,ttqqzz); | ||
clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); | clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); | ||
− | </asy> Allows most functions and can draw integrals and Riemman-like sums. Above, the function is given by <math>f(x) = 2+ | + | </asy> Allows most functions and can draw integrals and Riemman-like sums. Above, the function is given by <math>f(x) = 2+2\cos(2x)</math>; the four shaded regions are drawn using the commands '''Integral[f,-2pi,-pi], LowerSum[f,-pi,0,5], UpperSum[f,0,pi,5],''' and '''TrapezoidalSum[f,pi,2pi,5]'''. |
<geogebra>6636ccd3479762307d932c319db7ec1998236a4c</geogebra> | <geogebra>6636ccd3479762307d932c319db7ec1998236a4c</geogebra> | ||
Line 47: | Line 296: | ||
* May capitalize certain functions (like trigonometric functions). Please let me know if this happens. | * May capitalize certain functions (like trigonometric functions). Please let me know if this happens. | ||
* Certain functions recognized by Geogebra might not be recognized by Asymptote. | * Certain functions recognized by Geogebra might not be recognized by Asymptote. | ||
− | * Integrals/Sums drawn over functions that reach undefined values (ex, <math>ln(x)</math> at <math>x=0</math>) will cause a break when drawn in Asymptote (unlikely to be fixed); drawing the functions themselves will work, however. | + | * Integrals/Sums drawn over functions that reach undefined values (ex, <math>\ln(x)</math> at <math>x=0</math>) will cause a break when drawn in Asymptote (unlikely to be fixed); drawing the functions themselves will work, however. |
* With certain very contrived function strings, it is possible to break the code (won't fix). | * With certain very contrived function strings, it is possible to break the code (won't fix). | ||
* Sometimes will render LaTeX commands in function strings. Please let me know if this happens. | * Sometimes will render LaTeX commands in function strings. Please let me know if this happens. | ||
Line 136: | Line 385: | ||
Does '''BoxPlot[], Histogram[]''' commands, as well as background colors. | Does '''BoxPlot[], Histogram[]''' commands, as well as background colors. | ||
− | Known bugs: | + | Known bugs: none known |
+ | |||
+ | == Implicit functions == | ||
+ | Graph implicit functions that are polynomials in two variables <math>x,y</math> using Asymptote's <math>\texttt{contour}</math> package. | ||
+ | |||
+ | See [http://www.artofproblemsolving.com/Forum/viewtopic.php?f=519&t=408683 here]. | ||
+ | |||
+ | == Inequalities == | ||
+ | Graph a certain set of inequalities: functions, conics, and conjunction/disjunctions. (to do) | ||
== Full example == | == Full example == | ||
Line 149: | Line 406: | ||
<geogebra>9fa91fc57b9e5def39d73828270c8c027c565d85</geogebra> | <geogebra>9fa91fc57b9e5def39d73828270c8c027c565d85</geogebra> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 17:49, 17 October 2019
Gallery of examples: The following Asymptote codes were all generated from Geogebra files (File > Export > Graphics View as Asymptote ...). It is available in the current release of the Geogebra 4.0 Beta version. To download Geogebra 4.0, go here and either choose the webstart (direct) version or choose one of the 3.9 version offline installers (as beta versions, there may unfixed bugs, although the versions are for the most part stable.)
Contents
Documentation
Here is a fairly simple example that breaks down the contents of the output code, with Fill type set at "By layering".
Here is the Asymptote code produced: (with some spacing added)
/* Geogebra to Asymptote conversion, documentation at userscripts.org/scripts/show/72997 */ import graph; size(14.26cm); real labelscalefactor = 0.5; /* changes label-to-point distance */ pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ pen dotstyle = black; /* point style */ real xmin = -6.22,xmax = 8.04,ymin = -4.18,ymax = 4.76; /* image dimensions */ pen fueaev = rgb(0.96,0.92,0.9); pen zzttqq = rgb(0.6,0.2,0); real f2 (real x) {return sin(x);} filldraw(graph(f2,0,pi )--(pi ,0)--(0,0)--cycle, fueaev, zzttqq); filldraw((-3.14,0)--(0,0)--(0,3.14)--(-3.14,pi )--cycle, fueaev, zzttqq); Label laxis; laxis.p = fontsize(10); string xaxislabel (real x) { int n=round(x/pi); if(n==-1) return "<math>-\pi</math>"; if(n==1) return "<math>\pi</math>"; if(n==0) return "<math>0</math>"; return "<math>" + string(n) + "\pi</math>";} string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";} xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true); /* draw figures */ real f1 (real x) {return sin(x);} draw(graph(f1,-6.21,8.03)); draw((-3.14,0)--(0,0), zzttqq); draw((0,0)--(0,3.14), zzttqq); draw((0,3.14)--(-3.14,pi ), zzttqq); draw((-3.14,pi )--(-3.14,0), zzttqq); draw(circle((0,3.14),1.14)); draw(shift((3.35,2.06))*rotate(1)*xscale(1.59)*yscale(1.1)*unitcircle); pair hyperbolaLeft1 (real t) {return (0.49*(1+t^2)/(1-t^2),1.04*2*t/(1-t^2));} pair hyperbolaRight1 (real t) {return (0.49*(-1-t^2)/(1-t^2),1.04*(-2)*t/(1-t^2));} draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaLeft1,-0.99,0.99)); draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaRight1,-0.99,0.99)); /* hyperbola construction */ /* dots and labels */ label("<math>f</math>",(-6.12,-0.12),NE * labelscalefactor); label("<math>a = 2</math>",(1.46,0.24),NE * labelscalefactor,zzttqq); dot((-3.14,0),dotstyle); label("<math>A</math>",(-3.06,0.12),NE * labelscalefactor); dot((2.2,2.04),dotstyle); dot((4.5,2.08),dotstyle); clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); /* end of picture */
Here is a line-by-line explanation: ( are comments that are not read by the Asymptote engine.)
are the opening commands: any files that need to be imported (in this case, graph), followed by the horizontal size in centimeters, as shown by the Export to Asymptote window.
This variable scales the distance that labels are from their defined locations on the Geogebra window. This is due to an innate difference in the Asymptote and Geogebra treatment of labels: Geogebra positions labels with respect to a corner of the label, but Asymptote positions labels with respect to the center. Also, both have different default font sizes. The larger the value of , the farther the Asymptote labels are dislocated from their respective points. Usually, will have to be lowered to better position the labels (truer for longer labels). In concise mode, this variable is abbreviated as .
pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ pen dotstyle = black; /* point style */
These are the definition of the default pens to use. stands for default pen style and produces the default pen style. stands for the default dot style. In concise mode, the latter is abbreviated as , and in cse5, this option is completely replaced by the pen .
real xmin = -6.22,xmax = 8.04,ymin = -4.18,ymax = 4.76; /* image dimensions */ }
As the comment suggests, these four variables define the boundaries of the picture (in the units of the picture). Rays and lines that go out of the picture are defined in terms of these variables, as well as the clip window. Thus, changing these variables should keep intact most of the Asymptote contents.
pen fueaev = rgb(0.96,0.92,0.9); pen zzttqq = rgb(0.6,0.2,0);
These pens are custom defined colors, which are actually defined by hexadecimal values of the associated colors. The colors can be changed in this line (changing a specific shade to a darker shade, for example).
filldraw((-3.14,0)--(0,0)--(0,3.14)--(-3.14,pi )--cycle, fueaev, zzttqq);
This command draws a square in the picture. Of note is that if the axes are defined in terms of pi, then some coordinates are defined in terms of the Asymptote variable . The command changes to if the Fill type is set to "None".
real f2 (real x) {return sin(x);} filldraw(graph(f2,0,pi )--(pi ,0)--(0,0)--cycle, fueaev, zzttqq);
Some commands have to be defined with respect to a function. returns the function, and the command draws from to .
Label laxis; laxis.p = fontsize(10); string xaxislabel (real x) { int n=round(x/pi); if(n==-1) return "<math>-\pi</math>"; if(n==1) return "<math>\pi</math>"; if(n==0) return "<math>0</math>"; return "<math>" + string(n) + "\pi</math>";} string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";} xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true);
These commands draw the axes. The label specifies the label styles of the axes (e.g., the field defines the desired font pen).
The next line, the
string xaxislabel (real x) { int n=round(x/pi); if(n==-1) return "<math>-\pi</math>"; if(n==1) return "<math>\pi</math>"; if(n==0) return "<math>0</math>"; return "<math>" + string(n) + "\pi</math>";} string yaxislabel (real x) {return "<math>" + string(x) + "\,\mathrm{}</math>";}
are functions that define the labels for both axes. These are abbreviated as in the concise mode. The first defines axes with labels with respect to , and it formats the labels so that the label simply outputs instead of , and instead of . Finally,
xaxis("<math>x</math>",-6.22,8.04,Ticks(laxis,xaxislabel,Step=3.141592653589793,Size=2),Arrows(6),above=true); yaxis(-4.18,4.76,Ticks(laxis,yaxislabel,Step=1.0,Size=2),Arrows(6),above=true);
are the commands that actually construct the xaxis and the yaxis. For documentation, see here.
The next block of code does the actual construction of the geometric figures.
/* draw figures */ real f1 (real x) {return sin(x);} draw(graph(f1,-6.21,8.03)); draw((-3.14,0)--(0,0), zzttqq); draw((0,0)--(0,3.14), zzttqq); draw((0,3.14)--(-3.14,pi ), zzttqq); draw((-3.14,pi )--(-3.14,0), zzttqq); draw(circle((0,3.14),1.14)); draw(shift((3.35,2.06))*rotate(1)*xscale(1.59)*yscale(1.1)*unitcircle); pair hyperbolaLeft1 (real t) {return (0.49*(1+t^2)/(1-t^2),1.04*2*t/(1-t^2));} pair hyperbolaRight1 (real t) {return (0.49*(-1-t^2)/(1-t^2),1.04*(-2)*t/(1-t^2));} draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaLeft1,-0.99,0.99)); draw(shift((3.35,2.06))*rotate(1)*graph(hyperbolaRight1,-0.99,0.99)); /* hyperbola construction */
The first line real f1 (real x) {return sin(x);} defines the sin() function to be drawn, and the next line draw(graph(f1,-6.21,8.03)); actually draws the graph to the diagram. The graph() command comes from the Asymptote graph package. The next few lines draw several line segments. The attribute zzttqq is a pen whose color is mapped from some rgb value (with conversions ... 8 = y, 9 = z, a = a, b = b, ... ).
Options
An outline of the different available options.
(The first three options are related and automatically update with respect to eath other).
X/Y Units (cm): Indicates how many units in the picture correspond to 1 centimeter.
Picture width/height: Indicates what size the Asymptote output should be, in centimeters.
xmin/xmax/ymin/ymax: Indicates the dimensions of the picture in the picture's coordinates.
(The next options change other features).
Font size: Changes the default font size. The value defaults at 10pt, but I personally recommend 7pt for any file with multiple text lines, which more closely approximates the size of the font in the Geogebra window.
Fill type: This includes four options as to how Geogebra elements with different fill colors should be implemented:
- None: No fills are drawn.
- Only opaque fills. This will only cause filled objects with opaque transparencies, which are arbitrarily defined as shapes with transparency alpha values greater than 0.9 (on a 0 to 1, 1 being fully opaque, scale), to appear filled.
- With opacity pen. This uses the opacity() pen to draw transparency fills. This option does not work on the AoPS forums.
- By layering (my personal preference). Filled objects have "fake transparency" where filled objects are simply drawn before any other objects are drawn, and transparencies just cause a lighter shade. However, filled objects will override other filled objects, and so there is no "darker" transparencies along intersecting regions.
Concise code: This produces shorter Asymptote code. Some of the changes between non-concise and concise code:
- In non-concise code, most new commands have their own line. In concise code, there are at most about 8 lines of code.
- Abbreviations are used for certain variables (labelscalefactor to lsf, xaxislabel to xlbl, gridx to gx, and so forth).
- Pen colors are produced with a single line of pen declarations.
- Functions are re-used where possible.
- Less spacing.
The advantages of concise code:
- Less code to examine.
- Non-concise code will usually not render on the AoPS forums due to size limits.
- Guide to customizing code should be in the following posts.
The disadvantages of concise code:
- More difficult to read (especially without experience with my style of coding), exacerbated by lack of spacing.
- No documentation comments.
- Difficult to read through from given code window, requires wrap-around to read effectively.
Concise with cse5: There is also a cse5 option that allows the code to be further compactified with help with the cse5 package (see the stickies in this forum).
- In non-concise code, most new commands have their own line. In cse5 code, there are at most about 8 lines of code.
- Abbreviations are used for certain variables (labelscalefactor to lsf, xaxislabel to xlbl, gridx to gx, and so forth).
- Pairs are given names and produced in a single line; color pens are also produced in a single line.
- Functions are re-used where possible.
- Command shortcuts, such as MP() and D() are used extensively.
- Almost no spacing.
The advantages of cse5 code:
- Less code to examine.
- With the exception of excessively complicated diagrams, will almost always fit within AoPS size restrictions.
- Guide to customizing code should be in the following posts.
- Allows more customization; changing a declared point and pen will reflect changes across the code.
The disadvantages of cse5 code:
- Extremely difficult to read (especially without experience with my style of coding), exacerbated by lack of spacing and short commands.
- No documentation comments.
- Difficult to read through from given code window, requires wrap-around to read effectively.
- May occasionally draw skinny points and lines, due to default pathpen and pointpen attributes.
My personal recommendation is the concise code for producing quick sketches (cse5 for large quick sketches), and the non-concise code otherwise.
Grayscale: Uses monochromatic scale to produce all output.
Show Axes/Grid (default checked): Show or hide the axes and the grid.
Keep dot colors: Geogebra defaults free points to a blue color and semi-fixed points to a light blue color. Without this option checked, the Asymptote code will automatically set points to the default color (black). With checked, the Asymptote code will include the point colors as shown in the Geogebra window.
Use point names: (to do) In the Asymptote code, store points in variables rather than by write out by coordinates. Done by default for concise cse5 code.
Points
Support for drawing different options of points, along with point labeling.
Also includes an option to remove the coloring of just points (to avoid Geogebra's default of using different colors for different classes of fixed points).
<geogebra>1c89b124bb471a351bc108d34f8096d1f892e012</geogebra> (Note, the version of Geogebra here does not support different dot styles.)
Also has support for different types of axes: bold, with arrows, different colors, different labelling schemes (including with labels as in the next example). Also supports drawing of grid (with for loop constructions). There is a checkbox option to show and hide axes and grids.
Known bugs:
- Labels may be displaced more from points than shown in Geogebra window. This is not really a bug but a font problem, since Asymptote will write the labels in LaTeX, which has a different size from normal text. The recommended solution is to decrease the font size to fontsize(8) or fontsize(7).
- Leaving Keep Dot Colors() unchecked will color as black any labels which are a single character long and set to the default shade of blue for new points (presumably all such labels will be dot labels, which is the desired behavior).
- Some of the point styles might not be perfectly accurate when zoomed in.
- In cse5 mode, certain dots will appear smaller (default pointpen nature of cse5, not fixing).
Axes
There is support for drawing the x and y axes of the diagram (indeed, without Show Axes/Grid unchecked, and assuming the axes are visible in the Geogebra window, then the axes will be drawn). However, there are several bugs:
- The Asymptote code will remove the tick labels for . One can undo this by removing the attribute NoZero for the xaxis(), yaxis() commands. The reason is that the zero labels are not positioned well in Asymptote (indeed, the Geogebra tick labels for , or whatever the intersection point is, are shifted slightly)
- The location where the label of the axes (typically "x" or "y") will by default appear in the first quadrant ("x" above the x-axis, "y" to the right of the y-axis). In Asymptote, the labels appear in the exact opposite locations ("x" below the x-axis, "y" to the left of the y-axis). Low priority bug which is unlikely to be fixed.
- There is no (easy) support in Asymptote for having the x or y axes intersect at any point other than the origin. In GeoGebra, one can use the Crossing at textbox under Properties to change where the x-axis and y-axis intersects.
- Geogebra recognizes near-multiples of in axis tick distances; for example, if you enter an axis tick distance of , Geogebra automatically renders it as instead of . There's no easy way to do it in Asymptote (if you do want to try and mimic the behavior, manually add a labelling function which checks to see if tick labels are sufficient close to an integer multiple of . The code is too long to be worth included in general). Also, while labels are implemented, labels are soon to be introduced and have not been implemented.
Functions and Integrals
Allows most functions and can draw integrals and Riemman-like sums. Above, the function is given by ; the four shaded regions are drawn using the commands Integral[f,-2pi,-pi], LowerSum[f,-pi,0,5], UpperSum[f,0,pi,5], and TrapezoidalSum[f,pi,2pi,5].
<geogebra>6636ccd3479762307d932c319db7ec1998236a4c</geogebra>
Known bugs:
- May capitalize certain functions (like trigonometric functions). Please let me know if this happens.
- Certain functions recognized by Geogebra might not be recognized by Asymptote.
- Integrals/Sums drawn over functions that reach undefined values (ex, at ) will cause a break when drawn in Asymptote (unlikely to be fixed); drawing the functions themselves will work, however.
- With certain very contrived function strings, it is possible to break the code (won't fix).
- Sometimes will render LaTeX commands in function strings. Please let me know if this happens.
Lines and Conics
import graph; size(11.6cm); real lsf=0.5; pen dps=linewidth(0.7)+fontsize(10); defaultpen(dps); pen ds=black; real xmin=-5.06,xmax=6.54,ymin=-3.4,ymax=5.54; pen qqzztt=rgb(0,0.6,0.2), qqqqzz=rgb(0,0,0.6), ffqqtt=rgb(1,0,0.2);draw(circle((0,0),1),linewidth(2.8));draw((0,0)--(1,0)); draw((0,ymin)--(0,ymax)); draw((xmin,(-(3.19)-(1.03)*xmin)/3.02)--(xmax,(-(3.19)-(1.03)*xmax)/3.02)); draw((xmin,(-(-3.19)-(-0.88)*xmin)/3.06)--(xmax,(-(-3.19)-(-0.88)*xmax)/3.06)); draw(shift((-2.81,0.83))*rotate(54.75)*xscale(2.12)*yscale(1.91)*unitcircle,linewidth(1.6)+linetype("2pt 8pt 10pt 8pt")+qqzztt);pair hl1(real t){return (0.53*(1+t^2)/(1-t^2),0.74*2*t/(1-t^2));} pair hr1(real t){return (0.53*(-1-t^2)/(1-t^2),0.74*(-2)*t/(1-t^2));} draw(shift((3.63,0.55))*rotate(178.11)*graph(hl1,-0.99,0.99),linewidth(1.6)+linetype("4pt 4pt")+qqqqzz); draw(shift((3.63,0.55))*rotate(178.11)*graph(hr1,-0.99,0.99),linewidth(1.6)+linetype("4pt 4pt")+qqqqzz); real p1(real x){return x^2/2/3.48;} draw(shift((1.16,3.19))*rotate(16.04)*graph(p1,-13.93,13.93),linewidth(2)+ffqqtt); dot((0,0),ds); dot((1,0),ds); dot((-3.34,0.08),ds); dot((-2.28,1.58),ds); dot((-3.4,2.72),ds); dot((-0.94,0.34),ds); dot((2.72,0.58),ds); dot((4.54,0.52),ds); dot((0.68,4.86),ds); clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); (Error making remote request. Unknown error_msg)
Allows lines, rays, vectors (not shown), and the different conic sections (which includes circle arcs and sectors), including different line colors, line types, line sizes, and in some cases, fill colors. Lines and rays automatically re-scale to fit the entire window when the diagram size is changed.
<geogebra>f475aec9be4bbeb0d7a8b525fb2cbbe905383c5d</geogebra>
Known bugs:
- Broken line functions (floor, ceiling) graph incorrectly. Not likely to be fixed due to Asymptote's graph() design.
Filled objects
import graph; size(9.7cm); real lsf=0.5; pen dps=linewidth(0.7)+fontsize(10); defaultpen(dps); pen ds=black; real xmin=-3.58,xmax=6.12,ymin=-1.1,ymax=6.1; pen cqcqcq=rgb(0.75,0.75,0.75), fueaev=rgb(0.96,0.92,0.9), zzttqq=rgb(0.6,0.2,0), evefev=rgb(0.9,0.94,0.9), qqwuqq=rgb(0,0.39,0); filldraw((0,0)--(2,0)--(3.41,1.41)--(3.41,3.41)--(2,4.83)--(0,4.83)--(-1.41,3.41)--(-1.41,1.41)--cycle,fueaev,zzttqq); filldraw(arc((2,0),0.6,45,180)--(2,0)--cycle,evefev,qqwuqq); filldraw(arc((0,0),0.6,0,135)--(0,0)--cycle,evefev,qqwuqq); filldraw(arc((-1.41,1.41),0.6,-45,90)--(-1.41,1.41)--cycle,evefev,qqwuqq); filldraw(arc((-1.41,3.41),0.6,-90,45)--(-1.41,3.41)--cycle,evefev,qqwuqq); filldraw(arc((0,4.83),0.6,-135,0)--(0,4.83)--cycle,evefev,qqwuqq); filldraw(arc((2,4.83),0.6,180,315)--(2,4.83)--cycle,evefev,qqwuqq); filldraw(arc((3.41,3.41),0.6,135,270)--(3.41,3.41)--cycle,evefev,qqwuqq); filldraw(arc((3.41,1.41),0.6,90,225)--(3.41,1.41)--cycle,evefev,qqwuqq); /*grid*/ pen gs=linewidth(0.7)+cqcqcq+linetype("2pt 2pt"); real gx=1,gy=1; for(real i=ceil(xmin/gx)*gx;i<=floor(xmax/gx)*gx;i+=gx) draw((i,ymin)--(i,ymax),gs); for(real i=ceil(ymin/gy)*gy;i<=floor(ymax/gy)*gy;i+=gy) draw((xmin,i)--(xmax,i),gs); draw((0,0)--(2,0),zzttqq); draw((2,0)--(3.41,1.41),zzttqq); draw((3.41,1.41)--(3.41,3.41),zzttqq); draw((3.41,3.41)--(2,4.83),zzttqq); draw((2,4.83)--(0,4.83),zzttqq); draw((0,4.83)--(-1.41,3.41),zzttqq); draw((-1.41,3.41)--(-1.41,1.41),zzttqq); draw((-1.41,1.41)--(0,0),zzttqq); draw(arc((2,0),0.6,0.79,pi),qqwuqq); draw(arc((2,0),0.5,0.79,pi),qqwuqq); draw(arc((-1.41,1.41),0.6,-45,85.38),qqwuqq,BeginArcArrow(6)); draw(arc((-1.41,3.41),0.6,-90,40.38),qqwuqq,EndArcArrow(6)); draw(arc((0,4.83),0.6,-2.36,0),qqwuqq); draw((0.21,4.33)--(0.25,4.22),qqwuqq); draw((0.14,4.31)--(0.17,4.19),qqwuqq); draw((0.27,4.36)--(0.33,4.26),qqwuqq); draw(arc((2,4.83),0.6,pi,5.5),qqwuqq); draw((1.73,4.36)--(1.67,4.26),qqwuqq); draw((1.86,4.31)--(1.83,4.19),qqwuqq); draw(arc((3.41,3.41),0.6,2.36,4.71),qqwuqq); draw((2.92,3.21)--(2.8,3.16),qqwuqq); draw(arc((3.41,1.41),0.6,1.57,3.93),qqwuqq); draw(arc((3.41,1.41),0.5,1.57,3.93),qqwuqq); draw(arc((3.41,1.41),0.4,1.57,3.93),qqwuqq); draw((0,0)--(2,0),EndArrow(6)); dot((0,0),ds); dot((2,0),ds); dot((3.41,1.41),ds); dot((3.41,3.41),ds); dot((2,4.83),ds); dot((0,4.83),ds); dot((-1.41,3.41),ds); dot((-1.41,1.41),ds); label("$135^\circ$",(2.64,0.12),NE*lsf,qqwuqq); label("$135^\circ$",(0.28,0.78),NE*lsf,qqwuqq); label("$135^\circ$",(-1.1,2.06),NE*lsf,qqwuqq); label("$135^\circ$",(-0.72,3.28),NE*lsf,qqwuqq); label("$135^\circ$",(-1,4.68),NE*lsf,qqwuqq); label("$135^\circ$",(2.2,4.8),NE*lsf,qqwuqq); label("$135^\circ$",(3.38,3.64),NE*lsf,qqwuqq); label("$135^\circ$",(3.5,1.58),NE*lsf,qqwuqq); clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); (Error making remote request. Unknown error_msg)
Allows certain transparent fills. There are four possible options allowed for fill colors:
- No fills. Self-explanatory.
- Opaque fills only. This will only cause filled objects with opaque transparencies, which are arbitrarily defined as shapes with transparency alpha values greater than 0.9 (on a 0 to 1, 1 being fully opaque, scale), to appear filled.
- With opacity pen. This uses the opacity() pen to draw transparency fills. This option does not work on the AoPS forums.
- By layering (example above). Filled objects have "fake transparency" where filled objects are simply drawn before any other objects are drawn, and transparencies just cause a lighter shade. However, filled objects will override other filled objects, and so there is no "darker" transparencies along intersecting regions.
Polygons and angles, by default, will have transparent fill colors. Both have support for different line colors and fill colors (with different transparencies, colors, line sizes, etc). Angles include several different styles, including multiple arcs, tick marks, and arc arrows.
<geogebra>008edd5949bd2386cd1b9a7b223f16e44cbaf28c</geogebra>
Known bugs:
- Non re-sized arc arrows.
- Overlapping transparency colors do not sum together.
Text
import graph; size(11.58cm); real lsf=0.5; pen dps=linewidth(0.7)+fontsize(10); defaultpen(dps); pen ds=black; real xmin=-4.3,xmax=7.28,ymin=-2.64,ymax=6.3; pen cqcqcq=rgb(0.75,0.75,0.75), qqccqq=rgb(0,0.8,0), ccqqtt=rgb(0.8,0,0.2); /*grid*/ pen gs=linewidth(0.7)+cqcqcq+linetype("3pt 3pt"); real gx=1,gy=1; for(real i=ceil(xmin/gx)*gx;i<=floor(xmax/gx)*gx;i+=gx) draw((i,ymin)--(i,ymax),gs); for(real i=ceil(ymin/gy)*gy;i<=floor(ymax/gy)*gy;i+=gy) draw((xmin,i)--(xmax,i),gs); Label laxis; laxis.p=fontsize(10); xaxis(-4.3,7.28,defaultpen+black,Ticks(laxis,Step=1.0,Size=2),Arrows(6),above=true); yaxis(-2.64,6.3,defaultpen+black,Ticks(laxis,Step=1.0,Size=2),Arrows(6),above=true); label("abc",(-3,5.24),SE*lsf); label("a2 b3 c3 o pi e infty otimes sqrt(x)",(-3,4.24),SE*lsf); label("$\parbox{1.4 cm}{abc \\ def \\ ghi}$",(-3,3.24),SE*lsf); label("$ \sqrt{ abc } $",(-3,2.24),SE*lsf); label("$abc \\ def$",(-3,1.24),SE*lsf); label("$abc$",(-3,0.24),SE*lsf); label("$\alpha\beta\gamma$",(-3,-0.76),SE*lsf); label("alpha beta gamma ",(-3,-1.76),SE*lsf); label("\textit{\textbf{abc}}",(0,5.24),SE*lsf,qqccqq+fontsize(12)); label("\textit{\textbf{alpha beta gamma }}",(0,-1.76),SE*lsf,qqccqq+fontsize(12)); label("$\mathit{\mathbf{ \alpha\beta\gamma }}$",(0,-0.76),SE*lsf,ccqqtt+fontsize(12)); label("\textit{\textbf{$abc$}}",(0,0.24),SE*lsf,qqccqq+fontsize(12)); label("$\mathit{\mathbf{ abcdef }}$",(0,1.24),SE*lsf,ccqqtt+fontsize(12)); label("$\mathit{\mathbf{ \sqrt{ abc } }}$",(0,2.24),SE*lsf,ccqqtt+fontsize(12)); label("$\parbox{1.5 cm}{\textit{\textbf{abc \\ def \\ ghi}}}$",(0,3.24),SE*lsf,qqccqq+fontsize(12)); label("\textit{\textbf{a2 b3 co pi e infty otimes sqrt(x)}}",(0,4.24),SE*lsf,qqccqq+fontsize(12)); label("\textit{abc}",(3,5.24),SE*lsf,fontsize(8)); label("$\parbox{1.34 cm}{\textit{abc \\ def \\ ghi}}$",(3,3.24),SE*lsf,fontsize(8)); label("$\mathit{ \sqrt{ abc } }$",(3,2.24),SE*lsf,fontsize(8)); label("$\mathit{abcdef}$",(3,1.24),SE*lsf,fontsize(8)); label("\textit{$abc$}",(3,0.24),SE*lsf,fontsize(8)); label("\textit{alpha beta gamma }",(3,-1.76),SE*lsf,fontsize(8)); label("$\mathit{ \alpha\beta\gamma }$",(3,-0.76),SE*lsf,fontsize(8)); label("pi e infty otimes questeq ne le ge neg wedge vee parallel perp in subseteq subset cong equiv measuredangle triangle ",(3,4.24),SE*lsf); dot((-3,0),ds); dot((-3,1),ds); dot((-3,2),ds); dot((-3,3),ds); dot((-3,4),ds); dot((-3,5),ds); dot((0,5),ds); dot((0,4),ds); dot((0,3),ds); dot((0,2),ds); dot((0,1),ds); dot((0,0),ds); dot((0,-1),ds); dot((-3,-1),ds); dot((-3,-2),ds); dot((0,-2),ds); dot((3,5),ds); dot((3,4),ds); dot((3,3),ds); dot((3,2),ds); dot((3,1),ds); dot((3,0),ds); dot((3,-1),ds); dot((3,-2),ds); clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); (Error making remote request. Unknown error_msg)
Supports most text options, including different font styles, bold, italics, and .
<geogebra>087e142af582ed87e10a11362584f7ced9b606bd</geogebra>
Known bugs:
- Including text strings with dollar signs will convert it to LaTeX. An odd number of dollar signs in a text string will usually cause an error (working on for strings).
- Certain contrived strings will break the code (may never be fixed).
- Fontsize might not be correct occasionally, especially for cse5 commands. (Please let me know if this happens.)
Locus construction
Locus constructions with all of the usual lines options. Shown above is the "witch of aggensi".
<geogebra>d2594993982afff858b6296678b2bab7bbe351d8</geogebra>
Comment: Can create huge files.
Known bugs: none.
Statistics
Does BoxPlot[], Histogram[] commands, as well as background colors.
Known bugs: none known
Implicit functions
Graph implicit functions that are polynomials in two variables using Asymptote's package.
See here.
Inequalities
Graph a certain set of inequalities: functions, conics, and conjunction/disjunctions. (to do)
Full example
import graph; size(13.92cm); real lsf=0.5; pen dps=linewidth(0.7)+fontsize(10); defaultpen(dps); real xmin=-0.72,xmax=3.2,ymin=-1.81,ymax=1.35; pen ffqqcc=rgb(1,0,0.8), uququq=rgb(0.25,0.25,0.25), evefev=rgb(0.9,0.94,0.9), qqwuqq=rgb(0,0.39,0), evffff=rgb(0.9,1,1), qqffff=rgb(0,1,1); filldraw(arc((2.69,-1.5),0.16,134.59,180)--(2.69,-1.5)--cycle,evefev,qqwuqq); filldraw(arc((2,-0.8),0.16,-113.2,-90)--(2,-0.8)--cycle,evefev,qqwuqq); filldraw(arc((2,-1.5),0.16,0,90)--(2,-1.5)--cycle,evefev,qqwuqq); filldraw(arc((1.7,-1.5),0.16,0,66.8)--(1.7,-1.5)--cycle,evefev,qqwuqq); filldraw(arc((1.31,0),0.16,157.5,180)--(1.31,0)--cycle,evefev,qqwuqq); filldraw(arc((0.38,0),0.16,0,90)--(0.38,0)--cycle,evefev,qqwuqq); filldraw(arc((2.23,0),0.16,90,180)--(2.23,0)--cycle,evefev,qqwuqq); filldraw(arc((1.31,0),0.16,0,22.5)--(1.31,0)--cycle,evefev,qqwuqq); filldraw(arc((1.31,0),0.16,22.5,112.5)--(1.31,0)--cycle,evffff,qqffff); filldraw(arc((0,0),0.16,0,45)--(0,0)--cycle,evffff,qqffff); draw((xmin,(-(0)-(0)*xmin)/1)--(xmax,(-(0)-(0)*xmax)/1)); draw(circle((0,0),1.31),linetype("4pt 4pt")+blue);draw(circle((1.31,0),1),linetype("4pt 4pt")+red);draw((0.92,0.92)--(0,0),linewidth(1.6)); draw((0,0)--(1.31,0),linewidth(1.6)); draw((0.92,0.92)--(1.31,0),linewidth(1.6)); draw((1.31,0)--(2.23,0.38),linewidth(1.6)); draw((2.23,0.38)--(0.92,0.92),linewidth(1.6)); draw((0.38,0.38)--(2.23,0.38),ffqqcc); draw((0,0)--(2.23,0.38),ffqqcc); draw((2.23,0.38)--(2.23,0),dotted); draw((0,0.38)--(0,0),dotted); draw((0,0.38)--(0.38,0.38),dotted); draw((0.38,0.38)--(0.38,0.38),linewidth(1.2)+linetype("1pt 1pt")); draw((0.38,0.38)--(0,0),linewidth(1.2)+linetype("1pt 1pt")); draw((0.38,0.38)--(1.31,0),linewidth(1.2)+linetype("1pt 1pt")); draw((0.38,0.38)--(1.31,0),linewidth(1.2)+linetype("1pt 1pt")); draw((2.69,-1.5)--(2,-0.8)); draw((2,-0.8)--(1.7,-1.5)); draw((1.7,-1.5)--(2.69,-1.5)); draw((2,-0.8)--(2,-1.5)); label("$r $",(2.69,-1.84),SE*lsf); label("r",(2.3,-1.39),SE*lsf); label("$ r\sqrt{ 2 } $",(2.75,-1.24),SE*lsf); label("$r( \sqrt{ 2 } - 1 )$",(2.02,-1.85),SE*lsf); label("$45^\circ$",(2.41,-1.3),SE*lsf); label("$22.5^\circ$",(2.02,-0.96),SE*lsf); draw(circle((2.07,-1.43),0.01),qqwuqq); label("$90^\circ$",(2.15,-1.3),SE*lsf); label("$67.5^\circ$",(1.79,-1.28),SE*lsf); label("$22.5^\circ$",(0.84,0.1),SE*lsf); label("r",(0.71,-0.06),SE*lsf); label("$r( \sqrt{ 2 } - 1 )$",(0.27,0.35),SE*lsf); label("$r( \sqrt{ 2 } - 1 )$",(-0.05,-0.12),SE*lsf); label("$r( \sqrt{ 2 } - 1 )$",(-0.09,0.63),SE*lsf); label("$r( \sqrt{ 2 } - 1 )$",(-0.44,0.31),SE*lsf); draw(circle((0.45,0.07),0.01),qqwuqq); label("$90^\circ$",(0.6,0.1),SE*lsf); draw(circle((2.16,0.07),0.01),qqwuqq); label("$90^\circ$",(2.31,0.17),SE*lsf); label("$22.5^\circ$",(1.64,0.11),SE*lsf); label("r",(2.04,-0.09),SE*lsf); draw((1.4,-0.2)--(1.11,0.17),EndArrow(6));label("$ \sqrt{ (r (\sqrt{ 2 } - 1) + r + r )^2 + (r (\sqrt{ 2 } - 1) )^2 }$",(1.58,-0.2),SE*lsf); label("$ = \sqrt{ (r (\sqrt{ 2 } + 1) )^2 + (r (\sqrt{ 2 } - 1) )^2 } $",(1.53,-0.37),SE*lsf); label("$\mathbf{=r \sqrt{ 6 }}$",(1.53,-0.72),SE*lsf,blue); label("$= \sqrt{ r^2 (3 + 2 \sqrt{ 2 }) + r^2 (3 - 2 \sqrt{ 2 }) } $",(1.53,-0.54),SE*lsf); label("$\mathbf{2r}$",(1.46,0.64),SE*lsf,blue); label("$\mathbf{\frac{BE}{AE} = \frac{r \sqrt{ 6 }}{2r} = \frac{ \sqrt{ 6 }}{2}}$",(0.78,-1.47),SE*lsf,red+fontsize(14)); draw((1.74,-1.13)--(0.83,-0.06),EndArrow(6));draw(circle((1.34,0.09),0.01),qqffff); label("$45^\circ$",(-0.01,0.13),SE*lsf); label("$90^\circ$",(-0.22,1.47),SE*lsf); label("$90^\circ$",(1.39,0.24),SE*lsf); draw((0.38,0)--(0.38,0.38),linewidth(0.4)+dotted); dot((0,0),blue); label("$B$",(-0.06,-0.09),NE*lsf,blue); dot((1.31,0),blue); label("$D$",(1.34,-0.09),NE*lsf,blue); dot((0.92,0.92),blue); label("$C$",(0.91,0.99),NE*lsf,blue); dot((2.23,0.38),blue); label("$E$",(2.27,0.39),NE*lsf,blue); dot((0.38,0.38),blue); label("$A$",(0.33,0.41),NE*lsf,blue); dot((0.38,0),linewidth(1pt)+uququq); label("$G$",(0.41,-0.1),NE*lsf,uququq); dot((0,0.38),linewidth(1pt)+uququq); dot((2.23,0),linewidth(1pt)+uququq); label("$F$",(2.24,-0.1),NE*lsf,uququq); dot((0.38,0.38),uququq); dot((1.7,-1.5),blue); dot((2,-0.8),blue); dot((2.69,-1.5),blue); dot((2,-1.5),blue); clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle); (Error making remote request. Unknown error_msg)
Courtesy of User:Kouichi Nakagawa.
<geogebra>9fa91fc57b9e5def39d73828270c8c027c565d85</geogebra>