- Put the TPlot3D component on a form
- In the OnShow event add the following code:
// suppress any redraw during the // construction of the plot P3d.SuppressPaint := true; // adjust the data grid of the component P3d.GridMat.Resize(14,12); // fill the data grid for i:=1 to 14 do for j:=1 to 12 do P3d.GridMat[i,j] := Data[i,j]; // set the scales of the axes P3D.SetRange(1,14,1,12,0,35); // this triggers a repaint P3d.SuppressPaint := false;
- In the object inspector set the color model ("ColorCodingMode") to "cmThreeColors", the range of colors to a range of 0 to 35 (properties "ColorScaleLow" and "ColorScaleHigh"), and of course, the pivot colors ("ColorLow", "ColorMid", and "ColorHigh") according to your requirements.
You can download the sample program written for Delphi XE3 from here. The ZIP file contains the sources and the corresponding executable for Windows. In order to rotate the 3D plot simply click into the chart and drag the mouse holding the left mouse button down.
If you could write a sentence or two how to allow "holes" in the mesh, that would be great too.
ReplyDeleteAlso it seems that the default is that on the edges the surface goes to the bottom, but I would rather have it stop in "mid air" so to speak. I guess it is just a special kind of "hole".
It's easy to add holes: simply use the "OnBeforeRenderPolygon" event to decide whether to render the polygon or not (set "Handled" to TRUE in order to create a hole at the particular location).
ReplyDeleteThere's a nice sample application on the SDL Web site which shows how to program a surface with a hole:
http://www.lohninger.com/examples_part2.html
(look for the program "plot3dhole" on this page).
Regarding the edges: they are in no way connected to the bottom. It solely depends on the range of z-scale where the boundary of the surface appears (use, for example, "P3D.SetRange(1,14,1,12,-30,35);" in the sample code above, and the surface will appear "mid air").