title: Draw point by point 3D scatter plot with MathGL in C
body: <p>I am building a particle simulation, and I want to display each particle's position as a dot in a 3D scatter plot using <a href="http://mathgl.sourceforge.net/doc_en/Download.html#Download" rel="nofollow">MathGL</a> in C (not C++!). I am having trouble with the C interface.</p>
  
  <p>So far I found two interesting examples:</p>
  
  <ol>
  <li><p>A C++ example that seems to be close to what I want: <a href="http://mathgl.sourceforge.net/doc_en/Dots-sample.html" rel="nofollow">http://mathgl.sourceforge.net/doc_en/Dots-sample.html</a>  (but this is in C++, I have been unable to find the C-equivalent)</p></li>
  <li><p>This is a piece of C code that constructs a 3D surf plot with dots. </p>
  
  <pre><code>#include &lt;mgl2/mgl_cf.h&gt;
  int main()
  {
          HMGL gr = mgl_create_graph(600,400);
  
          HMDT a,x,y;
          a = mgl_create_data_size(30,40,1);
          x = mgl_create_data_size(30,1,1);
          y = mgl_create_data_size(40,1,1);
          mgl_data_modify(a,"pi*(1-2*x)*exp(-4*y^2-4*(2*x-1)^2)",0);
          mgl_data_fill(x,-1.,1.,'x');
          mgl_data_fill(y,0.,1.,'x');
          mgl_rotate(gr,40.,60.,0.);
          mgl_set_light(gr,1);
          mgl_box(gr,1);
          mgl_surf_xy(gr,x,y,a,".","");
          mgl_delete_data(a);
          mgl_delete_data(y);
          mgl_delete_data(x);
  
          mgl_write_frame(gr,"test.png","");
          mgl_delete_graph(gr);
          return 0;
  }
  </code></pre></li>
  </ol>
  
  <p>The example 2 is close to what I want to do, but it is annoying that <code>a</code> is not a linear array of just N particles. It also has to take a function to evaluate the values for <code>a</code> (z-axis) whereas I just want to pass the z-coordinate manually for each dot).</p>
  
  <p>My data is just a 1D array of structs, similar to this:</p>
  
  <pre><code>struct particle {
      double x, y, z, velocity;
  };
  </code></pre>
  
  <p>How do I plot these particles as dots in a 3D (scatter) plot with MathGL in C? I guess I have to use <code>mgl_dots</code>, but how does it read from my array of values? (I could use velocity as color coding, but that is optional)</p>