Asymptote: Difference between revisions

From FreeCAD Documentation
(Part_ColorPerFace)
 
(33 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
{{Page in progress}}
<translate>

</translate>
{{TOCright}}
{{TOCright}}
<translate>
== Introduction ==
[https://asymptote.sourceforge.io/ Asymptote] is a programming language with which you can create figures and graphs in two and three dimensions.


==Description== <!--T:13-->
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.


<!--T:14-->
The pdf-2D files generated from Asymptote codes can be viewed in any available pdf reader.
[https://asymptote.sourceforge.io/ Asymptote] is a vector language for 2D and 3D computer graphics. Asymptote code can be included in [https://www.latex-project.org/ LaTeX] documents or used to generate [https://en.wikipedia.org/wiki/PostScript PostScript], [[PDF|PDF]], [[SVG|SVG]], [https://www.khronos.org/webgl/ WebGL], and [https://en.wikipedia.org/wiki/PRC_(file_format) PRC] files. Interactive 3D PDF files created from Asymptote code require Acrobat Reader version 9 or higher.


<!--T:15-->
For the 3D figures obtained from [https://asymptote.sourceforge.io/ 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.
Asymptote support was added in FreeCAD version 0.19.


==Exporting== <!--T:16-->
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.


<!--T:17-->
In order to get a pdf-3d file using this method, some packages must or are recommended to be installed on your system:
# Optionally assign colors to the faces of the object you want to export with the [[Image:Part_ColorPerFace.svg|24px]] [[Part_ColorPerFace|Part ColorPerFace]] command.
*Needed: [https://sourceforge.net/projects/asymptote/ Asymptote compiler]
# Change to the [[Image:Workbench_Mesh.svg|24px]] [[Mesh Workbench|Mesh Workbench]].
*Needed if you want to embed the interactive figure into a document: A LaTeX system, for example [https://www.tug.org/texlive/ TeX Live]
# Create a mesh from the object with the [[Image:Mesh_FromPartShape.svg|24px]] [[Mesh_FromPartShape|Mesh FromPartShape]] command.
**Very useful: An Integrated LaTeX Editing Environment, for example [https://kile.sourceforge.io/ Kile] or [https://www.texstudio.org/ TeXstudio]
# Select the new mesh object.
# Invoke the [[Image:Mesh_Export.svg|24px]] [[Mesh_Export|Mesh Export]] command.
# Select the {{FileName|*.asy}} file format in the dialog box.
# Enter a filename.
# Press the {{Button|Save}} button.


==Converting== <!--T:18-->
== Exporting meshes to Asymptote code ==


<!--T:19-->
===Generating Asymptote code from FreeCAD.===
You need the [https://sourceforge.net/projects/asymptote/ Asymptote compiler] to convert {{FileName|*.asy}} files. To convert to PDF a [https://www.latex-project.org/get/ LaTeX] system is also required.
Thanks to the developer [https://forum.freecadweb.org/memberlist.php?mode=viewprofile&u=69 wmayer],
to date FreeCAD from version 0.19 -rev22411, can generate Asymptote codes from meshes created with the [[Image:Workbench_Mesh.svg|24px]] [[Mesh Workbench|Mesh Design Workbench]] .<br /> The process is the following:
#In a FreeCAD document, create a 3d object, using for example the [[Image:Workbench_Part.svg|24px]] [[Part Workbench|Part Workbench]] or [[Image:Workbench_PartDesign.svg|24px]] [[PartDesign Workbench|PartDesign Workbench]].
#* You can assign colors to the faces of your choice, as you would normally do:[[Image: coloringFaces.gif]]
#:# In the document [[tree view]], right-click the object you want to modify the colors.
#:# In the dialog that appears, select: "Set colors".
#:# 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.
#:# Press {{Button|Ok}}
# Change to the [[Image:Workbench_Mesh.svg|24px]] [[Mesh Workbench|Mesh Design Workbench]].
# Create a mesh of the desired object.
## With one click, select the object to export.
## From the menu, select {{MenuCommand|Meshes → Create mesh}}. Or equivalently, on the toolbar, click on [[Image:Mesh_FromPartShape.svg|32px]] [[Mesh_FromPartShape|Create mesh from shape...]] icon.
## In the [[Task panel]], select the desired options (such as colors, etc.) and then click the {{Button|Ok}}.
# Export the meshing to Asymptote code:
## Select the created mesh.
## On the toolbar press [[Image:Mesh_Export.svg|32px]] [[Mesh_Export|Export mesh...]] icon or follow the menu sequence: {{MenuCommand | Meshes → Export Mesh}}.
## In the lower part of the window that will appear, select the appropriate file type: Asymptote format (*.asy).
## Choose between leaving its default name or change it if you like, for example to AsymptoteFileName.asy.
# Ready, you have the Asymptote code with which you can generate, for example, a pdf file with the figure you selected in FreeCAD.


<!--T:20-->
== Generating a pdf file from the Asymptote code. ==
The compiler is a command line tool. To covert to PDF you can use this syntax:
# (People using a LaTeX GUI should configure it appropriately for compiling Asymptote code or LaTeX documents containning Asymptote code.)
{{Code|code=PathToAsyExecutable/asy -f pdf AsymptoteFileName.asy}}
# The Asymptote compiler is called asy.
# You can compile the generated file directly using the command line: {{Code|code=
$ asy -f pdf AsymptoteFileName.asy}}
# 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:{{Code|code=


==Related== <!--T:21-->
\documentclass[a4paper,10pt]{article}
...
\usepackage{asymptote}
...
\begin{document}
...
\begin{asy}
Asymptote Code goes here
\end{asy}
...
\end{document}
}} or {{Code|code=


<!--T:22-->
\documentclass[a4paper,10pt]{article}
* [[Import_Export|Import Export]]
...
\usepackage{asymptote}
...
\begin{document}
...
\begin{asy}
include "AsymptoteFileName.asy";
\end{asy}
...
\end{document}
}}
# Compile the files with the following command lines: {{Code|code=
$ pdflatex interactivePdf3D.tex
$ asy interactivePdf3D-*.asy
$ pdflatex interactivePdf3D.tex
}}
# At this point there will be a pdf-3D file: interactivePdf3D.pdf
# 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.


==Video tutorials== <!--T:23-->
== Related Pages ==


<!--T:24-->
* [[Import Export]]
The following videos are in Spanish:
* [[FreeCAD_Howto_Import_Export]]
* [https://www.youtube.com/watch?v=U0m3643Vb1Q A way of generating interactive pdf-3D files. (1/3) (From FreeCAD, MeshLab and LaTeX)]

* [https://www.youtube.com/watch?v=PhVNvDZIerM A way of generating interactive pdf-3D files. (2/3) (From Asymptote and LaTex)]
== Video tutorial ==
* [https://www.youtube.com/watch?v=Q_ufaCN2hb4 A way of generating interactive pdf-3D files. (3/3) (From FreeCAD, Asymptote and LaTeX)]
* [https://www.youtube.com/watch?v=Q_ufaCN2hb4 A way of generating interactive pdf-3D files. (3/3) (From FreeCAD, Asymptote and LaTeX)]
*[https://www.youtube.com/watch?v=PhVNvDZIerM A way of generating interactive pdf-3D files. (2/3)(From Asymptote and LaTex)]



== Related video tutorial ==
</translate>
*[https://www.youtube.com/watch?v=U0m3643Vb1Q A way of generating interactive pdf-3D files. (1/3)(From FreeCAD, MeshLab and LaTeX)]
== Related tutorials ==
{{Mesh Tools navi{{#translation:}}}}
{{Mesh Tools navi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
[[Category:Formats{{#translation:}}]]
[[Category:File_Formats{{#translation:}}]]

Latest revision as of 18:20, 13 April 2024

Other languages:

Description

Asymptote is a vector language for 2D and 3D computer graphics. Asymptote code can be included in LaTeX documents or used to generate PostScript, PDF, SVG, WebGL, and PRC files. Interactive 3D PDF files created from Asymptote code require Acrobat Reader version 9 or higher.

Asymptote support was added in FreeCAD version 0.19.

Exporting

  1. Optionally assign colors to the faces of the object you want to export with the Part ColorPerFace command.
  2. Change to the Mesh Workbench.
  3. Create a mesh from the object with the Mesh FromPartShape command.
  4. Select the new mesh object.
  5. Invoke the Mesh Export command.
  6. Select the *.asy file format in the dialog box.
  7. Enter a filename.
  8. Press the Save button.

Converting

You need the Asymptote compiler to convert *.asy files. To convert to PDF a LaTeX system is also required.

The compiler is a command line tool. To covert to PDF you can use this syntax:

PathToAsyExecutable/asy -f pdf AsymptoteFileName.asy

Related

Video tutorials

The following videos are in Spanish: