|
How to draw a standard semicircular sphere like matlab mesh function |
Posted by choujayyl on Mar-18-2025 14:38 |
|
There are two ways to set data in C++ ChartDirector's SurfaceChart.setData: 1. Grid data, 2. Scatter data. I currently need to draw a hemispherical surface using the grid data method, but I don't know how to do it.
matlab code:
phi1=0:pi/20:pi/2; theta1=0:pi/20:2*pi; [pp,tt]=meshgrid(phi1,theta1);
a1=R*sin(pp).*cos(tt); b1=R*sin(pp).*sin(tt); c1=-R*cos(pp);
mesh(a1,b1,c1);
This kind of data matrix is passed in, but if you use the scattered point method for the setData interface, it will internally interpolate and calculate the direct relationship between points, which is not what I want. I need to draw a standard hemispherical sphere. There are M x-coordinate data points and N y-coordinate data points. The interface also requires the x and y data points to be passed in incrementally. M * N z data points are passed in. I don't know how to pass them in?
Moreover, I also know that there is a rough method, using z = sqrt(R*R - x*x + y*y). However, the result drawn by this method is very rough and not what I need.
|
Re: How to draw a standard semicircular sphere like matlab mesh function |
Posted by Peter Kwan on Mar-19-2025 17:03 |
|
Hi choujayyl,
It should be possible to draw the mesh lines as in your attached image. This can be done by using custom lines.
It is more difficult if you want to draw the "surface" (that is, with all the cells filled). The surface itself can be smooth, but the border can be "rough", because ChartDirector will align the border to a rectangular grid. It is analogous to drawing a 2D circle by filling the cells in a 20 x 20 rectangular grid. I will try to see if I can work around by using higher density points near the border. Another possible work around is to draw it as a "texture" on a transparent surface.
Would you mind to clarify if you would like to draw the grid lines only, or the actual surface? (The following is an example of the grid lines and the surface.)
https://www.advsofteng.com/doc/cdcpp.htm#surfacewireframe.htm
Best Regards
Peter Kwan |
|