Asymptote

From FreeCAD Documentation
Revision as of 19:01, 24 December 2020 by Roy 043 (talk | contribs) (Some heavy editing...)
This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Description

Asymptote is a programming language for the creation of 2D and 3D computer graphics. Asymptote code can be included in a LaTeX document or used to generate PostScript, PDF, SVG, WebGL, and PRC files.

Interactive 3D PDF files created from Asymptote code required Acrobat Reader version 9 or higher. For other PDF files any PDF reader can be used.

Asymptote support was added in FreeCAD version 0.19.

Exporting

To generating Asymptote code do the following:

  1. In a FreeCAD document, create a 3d object, using for example the Part Workbench or PartDesign Workbench.
    • You can assign colors to the faces of your choice, as you would normally do by launching the context menu of the selected element in the tree view.
    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 panel, 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.

File:ColoringFaces.gif

Setting up the colors of the faces of an object by opening the context menu of the object in the tree view.

Generating a pdf file from the Asymptote code.

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


  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