Asymptote code can be included easily into a LaTeX document for generating (for example) a pdf file. If interested, see attachment, and read it with Acrobat Reader.wmayer wrote: ↑Thu Aug 27, 2020 3:13 pm Here is the content of a simple cube where the six sides have different colors:Save it as cube.asy.Code: Select all
/* * Created by FreeCAD <http://www.freecadweb.org> */ import three; size(500); // CA:Camera, OB:Camera currentprojection = orthographic(camera = (15, 5, 5), target = (5, 5, 5), showtarget = false, up = (0, 0, 1)); // ME:Mesh, OB:Mesh draw(surface((0, 10, 0)--(0, 0, 10)--(0, 10, 10)--cycle), rgb(1, 0.666667, 0)); draw(surface((0, 0, 0)--(0, 0, 10)--(0, 10, 0)--cycle), rgb(1, 0.666667, 0)); draw(surface((10, 0, 10)--(10, 10, 0)--(10, 10, 10)--cycle), rgb(0, 0, 1)); draw(surface((10, 0, 10)--(10, 0, 0)--(10, 10, 0)--cycle), rgb(0, 0, 1)); draw(surface((10, 0, 0)--(10, 0, 10)--(0, 0, 0)--cycle), rgb(0, 1, 0)); draw(surface((0, 0, 0)--(10, 0, 10)--(0, 0, 10)--cycle), rgb(0, 1, 0)); draw(surface((10, 10, 10)--(10, 10, 0)--(0, 10, 0)--cycle), rgb(0, 0.666667, 1)); draw(surface((10, 10, 10)--(0, 10, 0)--(0, 10, 10)--cycle), rgb(0, 0.666667, 1)); draw(surface((0, 10, 0)--(10, 10, 0)--(0, 0, 0)--cycle), rgb(0.333333, 0.666667, 0)); draw(surface((0, 0, 0)--(10, 10, 0)--(10, 0, 0)--cycle), rgb(0.333333, 0.666667, 0)); draw(surface((10, 10, 10)--(0, 10, 10)--(0, 0, 10)--cycle), rgb(1, 0, 0)); draw(surface((10, 10, 10)--(0, 0, 10)--(10, 0, 10)--cycle), rgb(1, 0, 0));
To render the content: asy -V cube.asy
To create a PDF file: asy -f pdf cube.asy -o cube.pdf
LaTeX Code, nameOfLaTeXFile.tex:
Code: Select all
\documentclass[a4paper,10pt]{article}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\usepackage{asymptote}
%opening
\title{Including Asymptote code into a \LaTeX{} document}
\author{ An author}
\begin{document}
\maketitle
\begin{abstract}
An abstract
\end{abstract}
\section{A section}
This is a section. Here an Asymptote code is included.
\begin{figure}[h!]
\centering
\begin{asy}
//Asymtote code can be written here directily or you can include an Asymptote file:
include "nameOfAsymptoteFile.asy";
\end{asy}
\caption{FreeCAD figure exported as Asymptote code}
\label{fig:aLabel}
\end{figure}
\section{Compiling \LaTeX{} document with an Asymptote code}
For obtaining a \textit{pdf} file from this \LaTeX{} document, compile in this way:
\begin{enumerate}
\item \textit{\$ pdflatex nameOfLaTexFile}
\item \label{it:compilingAsymptoteFile}\textit{\$ asy nameOfLaTexFile-1.asy}
\item \textit{\$ pdflatex nameOfLaTexFile}
\end{enumerate}
So, nameOfLaTexFile.pdf file will be generated. If more than one Asymptote code is included into the \LaTeX{} code, the item \ref{it:compilingAsymptoteFile} shoud be replaced by:
\begin{itemize}
\item \textit{\$ asy nameOfLaTexFile\-*.asy}
\end{itemize}
As for each Asymptote code included in the \LaTeX{} document, an Asymptote code, \textit{nameOfLaTexFile-i.asy, i=1,2$\ldots$} will be generated.
If you want to interact with the pdf-3D, read it with Acrobat Reader $\circledR$
\end{document}
Code: Select all
/*
* Created by FreeCAD <http://www.freecadweb.org>
*/
import three;
size(300); // replaced 500 by 300
// CA:Camera, OB:Camera
currentprojection = orthographic(camera = (15, 5, 5),
target = (5, 5, 5),
showtarget = false,
up = (0, 0, 1));
// ME:Mesh, OB:Mesh
draw(surface((0, 10, 0)--(0, 0, 10)--(0, 10, 10)--cycle),
rgb(1, 0.666667, 0));
draw(surface((0, 0, 0)--(0, 0, 10)--(0, 10, 0)--cycle),
rgb(1, 0.666667, 0));
draw(surface((10, 0, 10)--(10, 10, 0)--(10, 10, 10)--cycle),
rgb(0, 0, 1));
draw(surface((10, 0, 10)--(10, 0, 0)--(10, 10, 0)--cycle),
rgb(0, 0, 1));
draw(surface((10, 0, 0)--(10, 0, 10)--(0, 0, 0)--cycle),
rgb(0, 1, 0));
draw(surface((0, 0, 0)--(10, 0, 10)--(0, 0, 10)--cycle),
rgb(0, 1, 0));
draw(surface((10, 10, 10)--(10, 10, 0)--(0, 10, 0)--cycle),
rgb(0, 0.666667, 1));
draw(surface((10, 10, 10)--(0, 10, 0)--(0, 10, 10)--cycle),
rgb(0, 0.666667, 1));
draw(surface((0, 10, 0)--(10, 10, 0)--(0, 0, 0)--cycle),
rgb(0.333333, 0.666667, 0));
draw(surface((0, 0, 0)--(10, 10, 0)--(10, 0, 0)--cycle),
rgb(0.333333, 0.666667, 0));
draw(surface((10, 10, 10)--(0, 10, 10)--(0, 0, 10)--cycle),
rgb(1, 0, 0));
draw(surface((10, 10, 10)--(0, 0, 10)--(10, 0, 10)--cycle),
rgb(1, 0, 0));