Difference between revisions of "Asymptote: Macros and Packages"
(link) |
(→The Olympiad Package) |
||
Line 27: | Line 27: | ||
===The Olympiad Package=== | ===The Olympiad Package=== | ||
− | We have created an Olympiad package for Asymptote which includes macros for all the constructions that come up most often in Olympiad geometry problems! You can obtain the package olympiad.asy by clicking [[http://web.mit.edu/monks/www/olympiad.asy here]], and saving the page as "olympiad.asy" in your Asymptote directory (<tt>C:\Program Files\Asymptote</tt> by default). | + | We have created an Olympiad package for Asymptote which includes macros for all the constructions that come up most often in Olympiad geometry problems! You can obtain the package olympiad.asy by clicking [[http://web.mit.edu/monks/www/olympiad.asy here]], (the newer version with fewer bugs is available [http://www.artofproblemsolving.com/Forum/viewtopic.php?t=165767 here]) and saving the page/file as "olympiad.asy" in your Asymptote directory (<tt>C:\Program Files\Asymptote</tt> by default). |
This package includes the following definitions: | This package includes the following definitions: |
Revision as of 16:38, 17 March 2008
Asymptote (Vector Graphics Language) |
Getting Started - Basics - Drawing - Reference - Examples - Macros and Packages - Advanced Asymptote - 3D Graphics - Help |
Definitions
You can define your own functions in Asymptote. As an example, let's say you wanted to make a function called newfunction that takes a pair and a real value as input, and returns the pair . In addition, you want it to simply return the pair if no value of is specified, so you want to default to . The code would be as follows:
pair newfunction(pair z, real r=0) { real a,b; a=z.x; b=z.y; return (a+r,b+r); }
Put this definition in an asymptote document and then test it using some command like
draw(newfunction((20,30))--newfunction((20,30),30)--(0,0)--cycle);
See if it works!
Notice that the function must be declared a pair since it returns a pair, and each of the variables must be declared some data type too. The default value of was set to by , and the actual function procedure goes in between {}. This is the general format for a function definition.
Packages
Asymptote comes with several packages that contain useful functions for various purposes. For example, the package graph.asy contains the function
Circle(pair p, real r, int n=400);
which is a more accurate circle (having 400 nodes by default) than the built-in circle command. To use this function and others in graph.asy, simply put the command
import graph;
at the top of your Asymptote document.
You can create your own package by simply creating a new .asy file (say MyMacros.asy) with your own definitions in it, and saving it in the directory in which Asymptote is installed (C:\Program Files\Asymptote by default). Then import MyMacros; in your document, and you'll be set!
The Olympiad Package
We have created an Olympiad package for Asymptote which includes macros for all the constructions that come up most often in Olympiad geometry problems! You can obtain the package olympiad.asy by clicking [here], (the newer version with fewer bugs is available here) and saving the page/file as "olympiad.asy" in your Asymptote directory (C:\Program Files\Asymptote by default).
This package includes the following definitions:
Note: A sequence of variables without type declarations indicates that they are the same type as the variable preceding it. For example, the notation concurrent(pair A, B, C, D, E, F) indicates that all of the variables should have type pair.
* These boolean functions test for equality within ps points in order to avoid approximation errors.