4

I want to modify an Asymptote code that i found on this forum, but when i compile i get an empty page. I used Texstudio and Texmaker and the result is the same (an empty page). here is the code and link to the forum page. Draw realistic 3D crystal structures (diamond)

\documentclass{standalone}
\usepackage{asymptote}

\begin{document} \begin{asy} import three; settings.render=8; settings.prc=false; size(10cm);

//currentprojection=perspective((45,45,30)); currentprojection = orthographic((3,6,1));

material sphereCcolor = material(diffusepen=black, ambientpen=gray(0.1), specularpen=white); material cylcolor = material(diffusepen=white, ambientpen=white);

real cylRadius = 0.1; real sphereRadius = 0.25;

void drawRod(triple a, triple b) { surface rod = extrude(scale(cylRadius)unitcircle, axis=length(b-a)Z); triple orthovector = cross(Z, b-a); if (length(orthovector) > .01) { real angle = aCos(dot(Z, b-a) / length(b-a)); rod = rotate(angle, orthovector) * rod; } draw(shift(a)*rod, surfacepen=cylcolor); }

void drawCarbon(triple center) { draw(shift(center)scale3(sphereRadius)unitsphere, surfacepen=sphereCcolor); }

triple Aa = (0,0,0); triple Ab = 4X; triple Ac = 4Y; triple Ad = 4X+4Y; triple Ae = 2X+2Y; triple Ba = 1X+1Y+1Z; triple Bb = 3X+3Y+1Z; triple Ca = 2X+2Z; triple Cb = 2Y+2Z; triple Cc = 4X+2Y+2Z; triple Cd = 2X+4Y+2Z; triple Da = 3X+1Y+3Z; triple Db = 1X+3Y+3Z; triple Ea = 4Z; triple Eb = 4X+4Z; triple Ec = 4Y+4Z; triple Ed = 4X+4Y+4Z; triple Ee = 2X+2Y+4Z;

drawRod(Ba,Aa); drawRod(Ba,Ae); drawRod(Bb,Ae); drawRod(Bb,Ad); drawRod(Ba,Ca); drawRod(Ba,Cb); drawRod(Bb,Cc); drawRod(Bb,Cd); drawRod(Da,Ca); drawRod(Da,Cc); drawRod(Db,Cb); drawRod(Db,Cd); drawRod(Da,Eb); drawRod(Da,Ee); drawRod(Db,Ee); drawRod(Db,Ec);

drawCarbon(Aa); drawCarbon(Ab); drawCarbon(Ac); drawCarbon(Ad); drawCarbon(Ae); drawCarbon(Ba); drawCarbon(Bb); drawCarbon(Ca); drawCarbon(Cb); drawCarbon(Cc); drawCarbon(Cd); drawCarbon(Da); drawCarbon(Db); drawCarbon(Ea); drawCarbon(Eb); drawCarbon(Ec); drawCarbon(Ed); drawCarbon(Ee);

// Frame material framecolor = material(diffusepen=white, ambientpen=yellow); void drawFrame(triple a, triple b) { surface rod = extrude(scale(.5cylRadius)unitcircle, axis=length(b-a)Z); triple orthovector = cross(Z, b-a); if (length(orthovector) > .01) { real angle = aCos(dot(Z, b-a) / length(b-a)); rod = rotate(angle, orthovector) rod; } draw(shift(a)rod, surfacepen=framecolor); draw(shift(b)scale3(cylRadius)*unitsphere, surfacepen=framecolor); } drawFrame((0,0,0),4X); drawFrame((0,0,0),4Y); drawFrame((0,0,0),4Z); drawFrame(4X,4X+4Y); drawFrame(4X,4X+4Z); drawFrame(4Y,4Y+4X); drawFrame(4Y,4Y+4Z); drawFrame(4Z,4X+4Z); drawFrame(4Z,4Y+4Z); drawFrame(4X+4Y+4Z,4Y+4Z); drawFrame(4X+4Z,4X+4Y+4Z); drawFrame(4X+4Y,4X+4Y+4Z); \end{asy} \end{document}

This is the code in asymptote (page of the developper https://github.com/pivaldi) to get this figure: enter image description here

Sebastiano
  • 54,118
moumou85
  • 423
  • 1
    The code is broken (see the comment from "user25957" in the answer from where you have copied this code). material(diffusepen=white, ambientpen=yellow); don't work. So replace material sphereCcolor = material(diffusepen=black, ambientpen=gray(0.1), specularpen=white); by material sphereCcolor = green; and the two other similar lines by color like blue and red. In Asymptote, one error gives directly blank page. You need also to configure your LaTeX IDE to use the Asymptote toolchain. For the errors, perhaps the syntax has changed. – quark67 Mar 03 '23 at 13:11
  • 1
    ambientpen is officially gone: see https://sourceforge.net/p/asymptote/discussion/409349/thread/e5ca5b440f/. – quark67 Mar 03 '23 at 13:18
  • Thank you very much @quark67 for your answer. I changed "ambientpen" in the code and everything works fine with Texmaker, but with Texstudio I still have a blank page. – moumou85 Mar 03 '23 at 15:51
  • With Texstudio, have you tried Tools -> Commands -> Asymptote? Works for me with version 4.5.1. – quark67 Mar 03 '23 at 17:27
  • Yes, i tried Tools -> Commands -> Asymptote. I have the same version. – moumou85 Mar 03 '23 at 18:18
  • 1
    The compilation needs 3 step (pdflatex, asy, pdflatex). Go to Texstudio settings, Build section, and in "Build & view", select txs:///asy-pdf-chain chain. Then, click on ▶︎▶︎ (the Build & View button in the interface). You should read in messages "Process started: pdflatex ...", "Process started: asy ..." and again "Process started: pdflatex ..." where "..." contains options for the pdflatex command and the file name processed. For the asy command, the file name is appended with a "-1" before the extension ".asy", it's normal. If this don't work, edit your question with steps & screenshoots. – quark67 Mar 03 '23 at 23:18
  • I configured my Texstudio exactly as you showed me but i get the following error message "error: could not load module 'myfile-1.asy'" Process exited with error(s) – moumou85 Mar 04 '23 at 09:40
  • You probably need to ask a new question, as it's probably a configuration problem with Texstudio. But dummy question: does your file name contain a space? (cf. problem 4b at https://artofproblemsolving.com/wiki/index.php/Asymptote:_Help). See also this: https://tex.stackexchange.com/questions/455544/asymptote-could-not-load-module-filename-1-asy – quark67 Mar 04 '23 at 22:47
  • just a minor change from the code, test on http://asymptote.ualberta.ca/ Code 1/2 import three; size(10cm); currentprojection = orthographic((3,4,5)); real cylRadius = 0.1; real sphereRadius = 0.2; void drawRod(triple a, triple b) { surface rod = extrude(scale(cylRadius)*unitcircle, axis=length(b-a)*Z); triple orthovector = cross(Z, b-a); if (length(orthovector) > .01) { real angle = aCos(dot(Z, b-a) / length(b-a)); rod = rotate(angle, orthovector) * rod; } draw(shift(a)*rod, surfacepen=yellow); } – Black Mild Mar 06 '23 at 16:36
  • Code 2/2 void drawSphere(triple center) { draw(shift(center)*scale3(sphereRadius)*unitsphere, surfacepen=gray); } triple a=O,b=X,c=2Z; drawSphere(a); drawSphere(b); drawSphere(c); drawRod(a,b); drawRod(b,c); – Black Mild Mar 06 '23 at 16:36
  • My problem is that I can't compile with Texstudio. I tried with all the codes offered but I still get an error. – moumou85 Mar 06 '23 at 18:13

1 Answers1

2

I simplify the code for the connector rods. For embbeding on a LaTeX document, see this overleaf link.

enter image description here

// http://asymptote.ualberta.ca/
import three;
size(5cm);
currentprojection=orthographic((3,4,5));
void drawRod(triple a,triple b){
draw(a--b,blue+8pt);
}
triple[] A={O,X,2Z};
for(triple p : A)
draw(shift(p)*scale3(.2)*unitsphere,orange);

drawRod(A[0],A[1]); drawRod(A[1],A[2]);

Also have a look at this.

enter image description here

Black Mild
  • 17,569
  • I tried with this simplified the code but I still get an error. – moumou85 Mar 06 '23 at 18:14
  • @moumou85 I have fixed the code. Go on the site http://asymptote.ualberta.ca/, paste the code and click on "Run". It will work. Then, copy this code on a file with the extension .asy and on a Terminal go on the directory of the file and execute the command asyon it (asy myfile.asy). Normally, you obtain a file named myfile.eps(Encapsuled PostScript). Then delete the .eps file, open the .asy file with TexStudio, go to Tools, Compile, Asymptote. You will see in the "Messages" at botton of TexStudio that all is OK, and you will find the file myfile.eps alongside with the .asy file. – quark67 Mar 08 '23 at 03:11
  • @moumou85 For a .tex file (\documentclass, \begin{document} AND \begin{asy}), you need 3 passes (pdflatex, asy, pdflatex). All are in Tools, Compile, Asymptote in TexStudio. – quark67 Mar 08 '23 at 03:15
  • @moumou85 I updated an overleaf link (LaTeX online). Your problem is technical on how to setup your TexStudio, and it's not hard when following some (Bing, Google, this texSE forum) searches. – Black Mild Mar 08 '23 at 06:29
  • I know that with TexStudio i need 3 passes (pdflatex, asy, pdflatex) i do and i get "Process exited normally" but it gives blank page. – moumou85 Mar 08 '23 at 12:31