2

I want to make 3D animation in Asymptote: the blue small sphere moving along the 3D cyclic curve (that I named "orbit8"). I have heard that curves in Asymptote are parameterized. However, I don't know how to get positions of points along the orbit.

Could you please help me!

My MWE is as follows.

\documentclass{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
import three;
currentprojection=obliqueX;
unitsize(1cm);
draw(O--4 * X,Arrow3); 
draw(O--4 * Y,Arrow3); 
draw(-1*Z--4 * Z,Arrow3); 
label("$x$", 4 * X, NW);
label("$y$", 4 * Y, SE);
label("$z$", 4 * Z, E);
real a=.4;
triple U=(-a,-a,1),L=(a,a,1);
path3 orbit8=
(0,1,2)..(0,2,1)..(0,1,0)..U..(1,0,2)..(2,0,1)..(1,0,0)..L..cycle;
draw(orbit8,1bp+black);
dot(L,8bp+.8blue);
dot(U,5bp+.8red);
draw((0,0,2)--(0,0,4),6bp+green,Arrow3()); 
\end{asy}
\end{document}
  • 1
    Please use a MWE that contains the \documentclass, all the \usepackages (and libraries if you use tikz or something like that), as well as the \begin{document} and \end{document} – Vinccool96 Mar 13 '19 at 19:01
  • @Vinccool96 oh, it's usual in writing Asymptote code: just save with xxx.asy in Texmaker, then press F1 to typeset. Is that okay? – Black Mild Mar 13 '19 at 19:08
  • 1
    Something like this would be preferable – Vinccool96 Mar 13 '19 at 19:11
  • I have just improved my MWE as suggested. – Black Mild Mar 13 '19 at 19:22
3

You can use point(orbit8,t) where t is a time. I recommend this great tutorial as well as the asypictureB package by the author of the tutorial. That way you create the output with pdflatex -shell-escape <file>, where file could contain

\documentclass[border=3.14mm]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=asyani}
import three;
currentprojection=obliqueX;
unitsize(1cm);
draw(O--4 * X,Arrow3); 
draw(O--4 * Y,Arrow3); 
draw(-1*Z--4 * Z,Arrow3); 
label("$x$", 4 * X, NW);
label("$y$", 4 * Y, SE);
label("$z$", 4 * Z, E);
real a=.4;
triple U=(-a,-a,1),L=(a,a,1);
path3 orbit8=
(0,1,2)..(0,2,1)..(0,1,0)..U..(1,0,2)..(2,0,1)..(1,0,0)..L..cycle;
draw(orbit8,1bp+black);
dot(L,8bp+.8blue);
draw((0,0,2)--(0,0,4),6bp+green,Arrow3()); 
dot(point(orbit8,0.5),5bp+.8red);
\end{asypicture}
\end{document}

enter image description here

This is just for fun: creating an actual animation. This snippet creates a series of pdf files that can be converted to an animated gif as explained in this answer. Asymtote has its own facilities to produce animations, but I personally often use these methods (but this may just be me). The most important ingredient here is relpoint, which O.G. pointed out in the comments, so full credit goes to them.

\documentclass[border=3.14mm]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{orbiter.asf}
\begin{asypicture}{name=asyani}
import three;
currentprojection=obliqueX;
unitsize(1cm);
real mytime = @mytime;
draw(O--4 * X,Arrow3); 
draw(O--4 * Y,Arrow3); 
draw(-1*Z--4 * Z,Arrow3); 
label("$x$", 4 * X, NW);
label("$y$", 4 * Y, SE);
label("$z$", 4 * Z, E);
real a=.4;
triple U=(-a,-a,1),L=(a,a,1);
path3 orbit8=
(0,1,2)..(0,2,1)..(0,1,0)..U..(1,0,2)..(2,0,1)..(1,0,0)..L..cycle;
draw(orbit8,1bp+black);
dot(L,8bp+.8blue);
draw((0,0,2)--(0,0,4),6bp+green,Arrow3()); 
dot(relpoint(orbit8,mytime),5bp+.8red);
\end{asypicture}
\end{filecontents*}
\usepackage{asypictureB}
\standaloneenv{asypicture}
\usepackage{pgffor}
\begin{document}
\def\myangle{45}
\foreach \mytime in {0,0.025,...,0.975}
{
\RequireAsyRecompile
\input{orbiter.asf}
}
\end{document}

enter image description here

| improve this answer | |
  • thank you very much, marmot! i did not read the tutorial carefully. – Black Mild Mar 13 '19 at 21:40
  • 3
    From the documentation to access points at a given percentage relpoint(path p, real l) returns the point on path p at the relative fraction l of its arclength. – O.G. Mar 15 '19 at 8:43
  • @O.G. Thanks! Could you perhaps also add this information to tex.stackexchange.com/a/392518/121799 ? – user121799 Mar 15 '19 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.