5

I am generating large numbers (several thousand, say) of long random fractal path3s on a sphere (up to a few thousand points each), using an external program. I want to produce a 3D figure in Asymptote displaying these paths. Currently, my workflow is to use my external program to write all the data into a large Asymptote script and compile it.

This scheme works when I try very small examples (i.e. with dozens instead of thousands of paths), but it very quickly becomes prohibitively slow and memory intensive. I could write the data to a text file and read it into Asymptote instead, but this would be kind of ugly, and it seems unlikely that the bottleneck is parsing the .asy file. Also, this problem seems to be specific to 3D, so I'm hoping that there's some appropriate combination of 3D options---or something like that---that solves the problem.

It's hard to give a closely representative MWE given the external data generation, but this program (which displays a 10,000-step long random walk) captures the essential issue.

size(5cm);
import three;

triple q = (0.0,0.0,0.0);
path3 p = q;

for(int i=1;i<=10^4;++i){
  q = q + (2*unitrand()-1, 2*unitrand()-1, 2*unitrand()-1);
  p = p -- q;
}

draw(p);

TL;DR What's the best way to efficiently render many path3s?

6

You can greatly speed up your example by changing path3 to guide3 and drawing with a thin pen:

draw(p,thin());

See http://asymptote.sourceforge.net/doc/Paths-and-guides.html#index-guide

1
  • I tested 300, 600 and 900 iterations. With path3, I got 1.24s, 4.65s and 11.69s. With guide3, I got 0.55s, 1.04s and 1.41s. – Paul Gaborit Feb 22 '17 at 6:41

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.