当前位置: 首页 > 工具软件 > MathGL > 使用案例 >

mathgl java_使用C中的MathGL逐点绘制三维散点图(Draw point by point 3D scatter plot with MathGL in C)...

华凯捷
2023-12-01

I am building a particle simulation, and I want to display each particle's position as a dot in a 3D scatter plot using MathGL in C (not C++!). I am having trouble with the C interface.

So far I found two interesting examples:

A C++ example that seems to be close to what I want: http://mathgl.sourceforge.net/doc_en/Dots-sample.html (but this is in C++, I have been unable to find the C-equivalent)

This is a piece of C code that constructs a 3D surf plot with dots. #include

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;

}

The example 2 is close to what I want to do, but it is annoying that a is not a linear array of just N particles. It also has to take a function to evaluate the values for a (z-axis) whereas I just want to pass the z-coordinate manually for each dot).

My data is just a 1D array of structs, similar to this:

struct particle {

double x, y, z, velocity;

};

How do I plot these particles as dots in a 3D (scatter) plot with MathGL in C? I guess I have to use mgl_dots, but how does it read from my array of values? (I could use velocity as color coding, but that is optional)

 类似资料: