1

This is an extension to the question here. I tried the same logic for a multiparticle environment. I have around 100 particles in a cubic box. But I export only 10 particles for simplicity.

The rendering I get from Matlab is:

enter image description here

I received the following from the matlab2tikz:

enter image description here

Using the solution from the above link, I get this:

enter image description here

I need a different strategy here to achieve similar rendering to that of solution in the link for single particle.

Strangely, I also now notice that the ordering of the particles are different between the Matlab and the one from Matlab2tikz.

SKPS
  • 421
  • The code for the latter is here: https://pastebin.com/VS2hNwcs – SKPS Apr 26 '18 at 18:00
  • I'd like to politely convince you to draw such things with asymptote instead of matlab. The outcome will most likely more realistic, lead to a smaller file (at least at the level of the source code) and be less cumbersome to deal with. –  Apr 26 '18 at 20:37

1 Answers1

3

I know you asked for something else, but I could not resist showing you how simple it is to do such things with asympote. If you compile

\documentclass[border=3.14mm]{standalone}
\usepackage{asypictureB}
\begin{document}
% code essentially from https://tex.stackexchange.com/a/141478/121799
\begin{asypicture}{name=particles}
import three;
settings.render=8;
settings.prc=false;
settings.outformat = "pdf";
size(10cm);

currentprojection = orthographic((3,4,5));

material cylcolor = material(diffusepen=gray(0.9), ambientpen=gray(0.9));

real cylRadius = 0.1;
real sphereRadius = 0.1;

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 drawSphere(triple center) {
     draw(shift(center)*scale3(sphereRadius)*unitsphere, surfacepen=cylcolor);
}

void drawParticle(triple endA, triple endB){
drawSphere(endA);
drawSphere(endB);
drawRod(endA,endB);
}

drawParticle(O,0.5X);

drawParticle(Z,Z+0.5(X+Y)/sqrt(2));

drawParticle(2Z,2Z+0.5Y);

\end{asypicture}
\end{document}

with pdflatex -shell-escape, you'll get

enter image description here

I do not know the algorithm to place these things, but I can't imagine it will be hard to implement it in asymptote, or to let matlab write the relevant data into a piece of asymptote code.