Asymptote

From FreeCAD Documentation
Revision as of 13:46, 24 September 2020 by Jruiz (talk | contribs) (→‎Video tutorial)
This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Introduction

Asymptote is a programming language with which you can create figures and graphs in two and three dimensions.

An Asymptote program can be stored in a file and compiled individually. In this way, it is possible to generate eps or pdf files, among other formats. But you can also choose to include the Asymptote code in a LaTeX document. In this case, you can include the Asymptote code in the same file where you have the LaTeX document or, if you prefer, you can store the Asymptote program in another file and then include it in the file where you have the LaTeX code.

The pdf-2D files generated from Asymptote codes can be viewed in any available pdf reader.

For the 3D figures obtained from Asymptote programs, you can choose between creating a still image of the 3D figure from a chosen point of view or you can generate an interactive pdf-3D file. As in the former case, files containing static images can be read with any pdf file reader.

Until now, in order to interact with the pdf-3D files that are created using Asymptote, the Acrobat Reader program in version 9 or higher must be used.

In order to get a pdf-3d file using this method, some packages must or are recommended to be installed on your system:

  • Needed: Asymptote compiler
  • Needed if you want to embed the interactive figure into a document: A LaTeX system, for example TeX Live
    • Very useful: An Integrated LaTeX Editing Environment, for example Kile or TeXstudio

Exporting meshes to Asymptote code

Generating Asymptote code from FreeCAD.

Thanks to the developer wmayer, to date FreeCAD from version 0.19 -rev22411, can generate Asymptote codes from meshes created with the Mesh Design Workbench .
The process is the following:

  1. In a FreeCAD document, create a 3d object, using for example the Part Workbench or PartDesign Workbench.
    1. In the document tree view, right-click the object you want to modify the colors.
    2. In the dialog that appears, select: "Set colors".
    3. Next, in the 3D view, one face at a time, click on the desired face and then, in the task penel, click on the button that is just below Faces [] then you can select the color you decide.
    4. Press Ok
  2. Change to the Mesh Design Workbench.
  3. Create a mesh of the desired object.
    1. With one click, select the object to export.
    2. From the menu, select Meshes → Create mesh. Or equivalently, on the toolbar, click on Create mesh from shape... icon.
    3. In the Task panel, select the desired options (such as colors, etc.) and then click the Ok.
  4. Export the meshing to Asymptote code:
    1. Select the created mesh.
    2. On the toolbar press Export mesh... icon or follow the menu sequence: Meshes → Export Mesh.
    3. In the lower part of the window that will appear, select the appropriate file type: Asymptote format (*.asy).
    4. Choose between leaving its default name or change it if you like, for example to AsymptoteFileName.asy.
  5. Ready, you have the Asymptote code with which you can generate, for example, a pdf file with the figure you selected in FreeCAD.

Generating a pdf file from the Asymptote code.

  1. (People using a LaTeX GUI should configure it appropriately for compiling Asymptote code or LaTeX documents containning Asymptote code.)
  2. The Asymptote compiler is called asy.
  3. You can compile the generated file directly using the command line:
    $ asy -f pdf AsymptoteFileName.asy
    
  4. Or you can incorporate the code into a LaTeX document, say interactivePdf3D.tex by including the asymptote package in its preamble and then create an asymptote environment, where you can copy the generated Asymptote code or include the file AsymptoteFilename.asy:
    \documentclass[a4paper,10pt]{article}
    ...
    \usepackage{asymptote}
    ...
    \begin{document}
    ...
    \begin{asy}
    Asymptote Code goes here
    \end{asy}
    ...
    \end{document}
    
    or
    \documentclass[a4paper,10pt]{article}
    ...
    \usepackage{asymptote}
    ...
    \begin{document}
    ...
    \begin{asy}
    include "AsymptoteFileName.asy";
    \end{asy}
    ...
    \end{document}
    
  5. Compile the files with the following command lines:
    $ pdflatex interactivePdf3D.tex
    $ asy interactivePdf3D-*.asy
    $ pdflatex interactivePdf3D.tex
    
  6. At this point there will be a pdf-3D file: interactivePdf3D.pdf
  7. When reading it with Acrobat Reader, you will have the option of trusting the file once or always. If you agree to trust the file, after a click, you will be able to interact with the figure. You will be able rotate it, to pan it, as well as being able to zoom it in or out.

Related Pages

Video tutorials

Related video tutorial

Related tutorials