Difference between revisions of "Asymptote: 3D graphics"
Line 9: | Line 9: | ||
then change from using doubles to using triples as coordinates. Though some functions do not work when three is active. In order to fill a surface, for example, one must define a surface and draw that. instead of using [[asymptote: Filling|filldraw]]. This is also described <url>http://www.artofproblemsolving.com/Forum/viewtopic.php?f=519&t=399845 here</url>. | then change from using doubles to using triples as coordinates. Though some functions do not work when three is active. In order to fill a surface, for example, one must define a surface and draw that. instead of using [[asymptote: Filling|filldraw]]. This is also described <url>http://www.artofproblemsolving.com/Forum/viewtopic.php?f=519&t=399845 here</url>. | ||
+ | |||
+ | ===Data types=== | ||
+ | three defines the data types: | ||
+ | path3, (3D version of path) | ||
+ | guide3, (3D version of guide) | ||
+ | and surface (a surface bounded by a path(3)) | ||
+ | and other, less important ones. | ||
+ | ===Definitions=== | ||
+ | three defines the surfaces: | ||
+ | unitcube, unitsphere, unitdisk, unitplane, unitcylinder, unitcone, unitsolidcone, and unithemisphere | ||
==Projection== | ==Projection== | ||
You can use | You can use | ||
Line 48: | Line 58: | ||
draw(unitcube,palegrey); | draw(unitcube,palegrey); | ||
</asy> | </asy> | ||
+ | |||
+ | '''Note:''' When current projection is not given three tries to find the "best" view. | ||
==Interactive Projection== | ==Interactive Projection== | ||
When using Asymptote on your computer (not on AoPS), you can add some code that lets you rotate/pan/zoom with the mouse. | When using Asymptote on your computer (not on AoPS), you can add some code that lets you rotate/pan/zoom with the mouse. | ||
Line 59: | Line 71: | ||
</nowiki></pre> | </nowiki></pre> | ||
When compiling to PDF, it will allow you to rotate/pan/zoom with the mouse. | When compiling to PDF, it will allow you to rotate/pan/zoom with the mouse. | ||
− | ==Arrows== | + | ==Arrows and bars== |
− | Arrows in 3D are the same as in 2D except you add a 3 to the end of the name. | + | Arrows and bars in 3D are the same as in 2D except you add a 3 to the end of the name. |
Example. | Example. | ||
<pre><nowiki> | <pre><nowiki> | ||
import three; | import three; | ||
draw((0,0,0)--(1,1,1),green,Arrows3); | draw((0,0,0)--(1,1,1),green,Arrows3); | ||
+ | draw((0,1,0)--(1,0,1),blue,Bars3); | ||
</nowiki></pre> | </nowiki></pre> | ||
<asy> | <asy> | ||
import three; | import three; | ||
draw((0,0,0)--(1,1,1),green,Arrows3); | draw((0,0,0)--(1,1,1),green,Arrows3); | ||
+ | draw((0,1,0)--(1,0,1),blue,Bars3); | ||
</asy> | </asy> | ||
==Example== | ==Example== | ||
Line 111: | Line 125: | ||
==Other 3D Modules== | ==Other 3D Modules== | ||
Other modules in Asymptote that are for 3D are: | Other modules in Asymptote that are for 3D are: | ||
− | graph3, grid3, contour3 | + | graph3, grid3, contour3, and solids. |
Revision as of 15:26, 2 June 2011
Written by: <url> http://www.artofproblemsolving.com/Forum/memberlist.php?mode=viewprofile&u=81377 PythonNut</url>
Contents
[hide]Three
Three is a module in Asymptote that allows the user to create three dimensional graphics. Usually all you must do is import three,
import three;
then change from using doubles to using triples as coordinates. Though some functions do not work when three is active. In order to fill a surface, for example, one must define a surface and draw that. instead of using filldraw. This is also described <url>http://www.artofproblemsolving.com/Forum/viewtopic.php?f=519&t=399845 here</url>.
Data types
three defines the data types: path3, (3D version of path) guide3, (3D version of guide) and surface (a surface bounded by a path(3)) and other, less important ones.
Definitions
three defines the surfaces: unitcube, unitsphere, unitdisk, unitplane, unitcylinder, unitcone, unitsolidcone, and unithemisphere
Projection
You can use
currentprojection=orthographic(x,y,z);
To change current the view.
currentprojection=perspective(x,y,z);
Does the same thing, but is distorts the picture to imitate actual perspective.
Example:
base code:
import three; /* perspective line /* draw(unitcube,palegrey);
Using
currentprojection=orthographic(1,1/2,1/2);
We get a unit cube as:
Using
currentprojection=perspective(1,1/2,1/2);
We get a unit cube as:
Note: When current projection is not given three tries to find the "best" view.
Interactive Projection
When using Asymptote on your computer (not on AoPS), you can add some code that lets you rotate/pan/zoom with the mouse.
import settings; leftbutton=new string[] {"rotate","zoom","shift","pan"}; middlebutton=new string[] {"menu"}; rightbutton=new string[] {"zoom/menu","rotateX","rotateY","rotateZ"}; wheelup=new string[] {"zoomin"}; wheeldown=new string[] {"zoomout"};
When compiling to PDF, it will allow you to rotate/pan/zoom with the mouse.
Arrows and bars
Arrows and bars in 3D are the same as in 2D except you add a 3 to the end of the name. Example.
import three; draw((0,0,0)--(1,1,1),green,Arrows3); draw((0,1,0)--(1,0,1),blue,Bars3);
Example
import three; unitsize(1cm); size(200); currentprojection=perspective(1/3,-1,1/2); draw((0,0,0)--(1,0,0)--(1,1,0)--(0,1,0)--cycle,red); draw((0,0,0)--(0,0,1),red); draw((0,1,0)--(0,1,1),red); draw((1,1,0)--(1,1,1),red); draw((1,0,0)--(1,0,1),red); draw((0,0,1)--(1,0,1)--(1,1,1)--(0,1,1)--cycle,red); draw((0,0,0)--(1,0,0)--(1,1,0)--cycle,red); draw((0,0,0)--(1,1,0)--(1,1,1)--cycle,blue); label("$o$",(0,0,0),NW); label("$x=1$",(0.5,0,0),S); label("$y=1$",(1,1,0.5),E); label("$z=1$",(1,0.5,0),SE); label("$c$",(0.5,0.5,0.5),N);[/asy]
Which renders to
Other 3D Modules
Other modules in Asymptote that are for 3D are: graph3, grid3, contour3, and solids.