Difference between revisions of "User:Azjps/geogebra"
m |
m (→Statistics) |
||
Line 136: | Line 136: | ||
Does '''BoxPlot[], Histogram[]''' commands, as well as background colors. | Does '''BoxPlot[], Histogram[]''' commands, as well as background colors. | ||
− | Known bugs: | + | Known bugs: none known |
== Full example == | == Full example == |
Revision as of 00:08, 18 February 2011
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.
Contents
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).
- In cse5 mode, certain dots will appear smaller (default pointpen nature of cse5, not fixing).
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
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>
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.
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:
/* 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: (/* COMMENT */
are comments that are not read by the Asymptote engine.)
import graph; size(14.26cm);
These 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.
real labelscalefactor = 0.5; /* changes label-to-point distance */
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 labelscalefactor
, the farther the Asymptote labels are dislocated from their respective points. Usually, labelscalefactor
will have to be lowered to better position the labels (truer for longer labels). In concise mode, this variable is abbreviated as lsf
.
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. dps
stands for default pen style and produces the default pen style. dotstyle
stands for the default dot style. In concise mode, the latter is abbreviated as ds
, and in cse5, this option is completely replaced by the pen pointpen
.
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 filldraw
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 pi
. The command changes to draw
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. f2
returns the function, and the graph
command draws f2
from to .
Label laxis; laxis.p = fontsize(10); string xaxislabel (real x) {int n=round(x/pi); if(n==-1) return ""; if(n==1) return ""; if(n==0) return ""; return "";} string yaxislabel (real x) {return "";}
xaxis("",-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 laxis
label specifies the label styles of the axes (e.g., the field laxis.p
defines the desired font pen).
The next line, the string xaxislabel (real x) {int n=round(x/pi); if(n==-1) return ""; if(n==1) return ""; if(n==0) return ""; return "";} string yaxislabel (real x) {return "";}
are functions that define the labels for both axes. These are abbreviated as xlbl, ylbl
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 .