Problem with Surface plot

Have a suggestion for improving DPlot or a question about existing features? Let us know

Moderator: DPlotAdmin

Post Reply
Peter
Posts: 10
Joined: Mon Aug 24, 2009 9:10 am

Problem with Surface plot

Post by Peter »

I have a problem with 3D surface display.
My application is a Win32 program . The surface is defined as a 2D matrix with the size of Hcell-by-Vcell The surface height is defined as the value of the matrix elements, the x and y coordinates as the indecies of the matrix elements.
The matrix is stored in a double precision linear array Surf3d with the size of (Hcell+1)*(Vcell+1)
The surface values are arranged in the linear array as:

Code: Select all

					for (r=0;r<Vcell;r++) { // rows
						for (c=0;c<Hcell;c++) { // columns
							i = r*Hcell + c;
							Surf3d[i] = (double)rec[i];
						}
					}
rec are the experimentally measured surface data.
When I save the Surf3d array and display in Excel using Excel's native surface plot I see a completely acceptable surface.

I my program I try to display using



Code: Select all

                /* Initialize DPLOT structure to 0's: */
                memset(&DPlot,0,sizeof(DPlot));

                /* Fill in members of DPLOT structure */
                DPlot.Version    = DPLOT_DDE_VERSION;
                DPlot.hwnd       = (DWORD)hDlg;
                DPlot.DataFormat  = DATA_3D;
                DPlot.MaxCurves  = Hcell;
                DPlot.MaxPoints  = Vcell;
                DPlot.NumCurves  = 1;
                DPlot.Scale      = SCALE_LINEARX_LINEARY;
                strcpy(DPlot.Title[0],"The surface");
                strcpy(DPlot.XAxis,"X");
                strcpy(DPlot.YAxis,"Y");

                Lighting = 0;
                GetDlgItemText(hDlg,IDC_XRANGEEDIT,szText,sizeof(szText));
                xhi = atof(szText);
                GetDlgItemText(hDlg,IDC_YRANGEEDIT,szText,sizeof(szText));
                yhi = atof(szText);
                GetDlgItemText(hDlg,IDC_ZLORANGEEDIT,szText,sizeof(szText));
                zlo = atof(szText);
                GetDlgItemText(hDlg,IDC_ZHIRANGEEDIT,szText,sizeof(szText));
                zhi = atof(szText);
                xlo = 0.0; ylo=0.0;

                //if(Is3DView)
                sprintf_s(szExec, 1024,"[Caption(\"Heatbump plot\")]"
                          "[Contour3D(1)][ContourView(%d,20)][ContourLighting(%d,0.05)]", (int)angle, Lighting);

                sprintf_s(line, 1000, "[ContourGrid(0)][ContourAxes(1)][ContourMethod(0)][ContourLevels(20,%.3f, %.3f)]"
                          "[ContourScales(1,1,%d)][ManualScale(0,0,%.3f, %.3f,%.3f,%.3f)]"
                          "[FontPoints(1,8)][FontPoints(2,12)][FontPoints(3,12)]"
                          "[FontPoints(4,10)][FontPoints(5,10)][FontPoints(6,8)][FontPoints(8,10)]"
                          "[ZAxisLabel(\"Height\")][DocMaximize()]", MinRec, MaxRec, 5, xhi, yhi, zlo, zhi);

                strcat(szExec, line);


                if (hbmp) {
                    DeleteObject(hbmp);
                    hbmp = 0;
                }
                if (DocNum) dPlot_Command(DocNum, "[FileClose()]");
				DocNum = dPlot_Plot8(&DPlot, extents, Surf3d, szExec);
                if (DocNum) {
                    SetBitmapToFrame();
                    Is3D = 1;
                }
                free(z);

The Surface shown by dplot is very different from what I see from the Excel display:
The surface I am supposed to see in dplot is an inclined plane (as it show up in Excel surface plot) but with the dplot it looks like a plane surface with a warp aling the (i,i) line.

Any idea what could cause this defect?
Peter
Peter
Posts: 10
Joined: Mon Aug 24, 2009 9:10 am

Post by Peter »

I wanted to attach a word doc with the two plots - I don't know how....
Peter
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

No attachments here, sorry. You're welcome to send files to support@dplot.com if you think it is necessary after this.

It looks to me like your loop limits and the calculation of i aren't correct, should be:

Code: Select all

for (r=0;r<Vcell+1;r++) { // rows 
    for (c=0;c<Hcell+1;c++) { // columns 
        i = r*(Hcell+1) + c; 
        Surf3d[i] = (double)rec[i]; 
    } 
} 
Visualize Your Data
support@dplot.com
Peter
Posts: 10
Joined: Mon Aug 24, 2009 9:10 am

Post by Peter »

DPlotAdmin wrote:No attachments here, sorry. You're welcome to send files to support@dplot.com if you think it is necessary after this.

It looks to me like your loop limits and the calculation of i aren't correct, should be:

Code: Select all

for (r=0;r<Vcell+1;r++) { // rows 
    for (c=0;c<Hcell+1;c++) { // columns 
        i = r*(Hcell+1) + c; 
        Surf3d[i] = (double)rec[i]; 
    } 
} 

David, I don't quite get it:
The double-loop in your code snippet implies that the array has a dimension of Hcell+1 by Vcell+1.
In reality there are Hcell elements horizonally and Vcell elements vertically.
Peter
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

OK, in that case this:

Code: Select all

DPlot.MaxCurves  = Hcell;
DPlot.MaxPoints  = Vcell; 
should be

Code: Select all

DPlot.MaxCurves  = Hcell-1;
DPlot.MaxPoints  = Vcell-1; 
And I probably need to do a better job of explaining this in the example source. Those are the number of rectangular grid cells in each direction (1 less than the number of points).
Visualize Your Data
support@dplot.com
Post Reply