Difference between revisions of "Asymptote: Useful commands and their Output"

Line 3: Line 3:
 
For each of the following, we have put a blue dot at the origin in order to indicate relative location of the output on the coordinate plane.  In other words, assume that before each of the examples below is the command  
 
For each of the following, we have put a blue dot at the origin in order to indicate relative location of the output on the coordinate plane.  In other words, assume that before each of the examples below is the command  
 
  <tt>dot((0,0),blue);</tt>
 
  <tt>dot((0,0),blue);</tt>
In addition, a comment after a line such as <tt>//math</tt> indicates that the command used in that line is defined in the <tt>math</tt> package, thus motivating the <tt>include math;</tt> (or other appropriate package) line at the top of the example.
+
In addition, a comment after a line such as <tt>//math - extension</tt> indicates that the command (in this case extension) used in that line is defined in the <tt>math</tt> package, thus motivating the <tt>include math;</tt> (or other appropriate package) line at the top of the example.
  
 
----
 
----
Line 35: Line 35:
 
  pair A,B,C,D,E;
 
  pair A,B,C,D,E;
 
  A=(0,0); C=(50,0); B=(10,10); D=(40,20);
 
  A=(0,0); C=(50,0); B=(10,10); D=(40,20);
  E=extension(A,B,C,D);  // extension is a command from the math package
+
  E=extension(A,B,C,D);  // math - extension
  // that returns the intersection of lines AB and CD
+
  // extension(A,B,C,D) returns the intersection of lines AB and CD
 
  draw(A--B); draw(C--D);
 
  draw(A--B); draw(C--D);
 
  draw(B--E--D,orange);
 
  draw(B--E--D,orange);
Line 47: Line 47:
 
'''Example 5:'''
 
'''Example 5:'''
 
  include graph;
 
  include graph;
  draw(Circle((0,0),20));
+
  draw(Circle((0,0),20)); // graph - Circle
 
'''Output 5:'''
 
'''Output 5:'''
 
[[Image:Figure6.gif]]
 
[[Image:Figure6.gif]]
Line 70: Line 70:
 
  pair A,B,C,O,I;
 
  pair A,B,C,O,I;
 
  A=origin; B=2*right; C=1.5*dir(70);
 
  A=origin; B=2*right; C=1.5*dir(70);
  O=circumcenter(A,B,C); // circumcenter is a command in the Olympiad package
+
  O=circumcenter(A,B,C); // olympiad - circumcenter
  I=incenter(A,B,C); // incenter is a command in the Olympiad package
+
  I=incenter(A,B,C); // olympiad - incenter
 
  draw(A--B--C--cycle);
 
  draw(A--B--C--cycle);
 
  dot(O);
 
  dot(O);
 
  dot(I);
 
  dot(I);
  draw(circumcircle(A,B,C));
+
  draw(circumcircle(A,B,C)); // olympiad - circumcircle
  draw(incircle(A,B,C));
+
  draw(incircle(A,B,C)); // olympiad - incircle
 
  label("<math>I</math>",I,W);
 
  label("<math>I</math>",I,W);
 
  label("<math>O</math>",O,S);
 
  label("<math>O</math>",O,S);
Line 86: Line 86:
  
 
'''Example 8:'''
 
'''Example 8:'''
  import three;
+
  include three;
 
  unitsize(1inch);
 
  unitsize(1inch);
  currentprojection=orthographic(1/2,-1,1/2);
+
  currentprojection=orthographic(1/2,-1,1/2); // three - currentprojection, orthographic
  draw((0,0,0)--(1,0,0)--(1,1,0)--(0,1,0)--cycle3,red);
+
  draw((0,0,0)--(1,0,0)--(1,1,0)--(0,1,0)--cycle3,red); //three - cycle3
 
  draw((0,0,0)--(0,0,1));
 
  draw((0,0,0)--(0,0,1));
 
  draw((0,1,0)--(0,1,1));
 
  draw((0,1,0)--(0,1,1));

Revision as of 17:24, 3 February 2007

Asymptote (Vector Graphics Language)
Getting Started - Basics - Drawing - Labeling - Filling - Useful functions - Examples - Macros and Packages

Help - Reference - Advanced Asymptote - 3D Graphics - CSE5 Package - How to

For each of the following, we have put a blue dot at the origin in order to indicate relative location of the output on the coordinate plane. In other words, assume that before each of the examples below is the command

dot((0,0),blue);

In addition, a comment after a line such as //math - extension indicates that the command (in this case extension) used in that line is defined in the math package, thus motivating the include math; (or other appropriate package) line at the top of the example.


Example 1:

dot((20,0));

Output 1: Figure2.gif


Example 2:

draw((0,0)--(50,0),BeginArrow);
draw((0,-10)--(50,-10),MidArrow);
draw((0,-30)--(50,-30),Arrows);

Output 2: Figure3.gif


Example 3:

draw((0,0)--(50,0));
arrow((30,0),dir(180),green);

Output 3: Figure4.gif


Example 4:

include math;
pair A,B,C,D,E;
A=(0,0); C=(50,0); B=(10,10); D=(40,20);
E=extension(A,B,C,D);  // math - extension
// extension(A,B,C,D) returns the intersection of lines AB and CD
draw(A--B); draw(C--D);
draw(B--E--D,orange);

Output 4: Figure5.gif


Example 5:

include graph;
draw(Circle((0,0),20)); // graph - Circle

Output 5: Figure6.gif


Example 6:

path p=(0,0)..(20,15)..(40,-5)..(50,0);
draw(p);
draw(rotate(90)*p,green);
draw(rotate(180,(-5,0))*p,orange);
draw(shift((5,20))*p,magenta);
draw(shift((0,-25))*yscale(1.4)*p,red);

Output 6: Figure7.gif


Example 7:

include olympiad;
pair A,B,C,O,I;
A=origin; B=2*right; C=1.5*dir(70);
O=circumcenter(A,B,C); // olympiad - circumcenter
I=incenter(A,B,C); // olympiad - incenter
draw(A--B--C--cycle);
dot(O);
dot(I);
draw(circumcircle(A,B,C)); // olympiad - circumcircle
draw(incircle(A,B,C)); // olympiad - incircle
label("$I$",I,W);
label("$O$",O,S);

Output 7: Figure8.gif


Example 8:

include three;
unitsize(1inch);
currentprojection=orthographic(1/2,-1,1/2); // three - currentprojection, orthographic
draw((0,0,0)--(1,0,0)--(1,1,0)--(0,1,0)--cycle3,red); //three - cycle3
draw((0,0,0)--(0,0,1));
draw((0,1,0)--(0,1,1));
draw((1,1,0)--(1,1,1));
draw((1,0,0)--(1,0,1));
draw((0,0,1)--(1,0,1)--(1,1,1)--(0,1,1)--cycle3,green);

Output 8: Figure9.gif