Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Plot 3D Parametric Surface method on 3DGraph control

Hi guys
 
I need to  plot a sphere surface in 3DGraph control so I write down the following code.
 
private void PlotSphere( double radius, int resolution)
  {
   int i, j;
   double[,] elementX = new double[resolution,resolution];
   double[,] elementY = new double[resolution,resolution];
   double[,] elementZ = new double[resolution,resolution];
   for( j = 0; j < 25; j ++)
   {
    temp = radius * Math.Sin(( j - resolution / 2) * Math.PI / resolution);
    for( i = 0; i < 25; i++)
    {
     elementX[j,i] = radius * Math.Cos( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
     elementY[j,i] = radius * Math.Sin( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
     elementZ[j,i] = temp;
    }
   }
   axCWGraph3D1.Plot3DParametricSurface( elementX, elementY, elementX, null );
         
  }
 
 
 
When compile MS.NET2003 show me that"Array dimension mismatch."
Could you help to find out the root cause?
********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 1 of 7
(4,394 Views)

Hi

   try
   {
    int i, j;
    double[,] elementX = new double[resolution,resolution];
    double[,] elementY = new double[resolution,resolution];
    double[,] elementZ = new double[resolution,resolution];
    double[,] colorArray = new double[25, 25];
    Random random = new Random();
    /*for( j = 0; j < 25; j ++)
    {
     for( i = 0; i < 25; i++)
     {
      elementX[j,i] = random.Next(1);
      elementY[j,i] = random.Next(1);
      elementZ[j,i] = random.Next(1);
     }
    }*/
    double temp;
    for( j = 0; j < 25; j ++)
    {
     temp = radius * Math.Sin(( j - resolution / 2) * Math.PI / resolution);
     for( i = 0; i < 25; i++)
     {
      elementX[i,j] = radius * Math.Cos( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
      elementY[i,j] = radius * Math.Sin( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
      elementZ[i,j] = temp;
      colorArray[i,j] = random.Next(1);
     }
    }
    //axCWGraph3D1.Plot3DParametricSurface( elementX, elementY, elementX, null );
    axCWGraph3D1.Plots.RemoveAll();
    //axCWGraph3D1.Plots.Add();
    
    axCWGraph3D1.Plot3DParametricSurface(elementX, elementY, elementZ,colorArray);
    axCWGraph3D1.Plots.Item(1).Style = CW3DGraphLib.CWPlot3DStyles.cwSurfaceLine;
   }

I just pass down the random array to 4th parameter , 3DGraph plots out like attachment picture.

 

How to use 4th parameter in this method "Plot3DParametricSurface"?

********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 2 of 7
(4,387 Views)

Hi

   try
   {
    int i, j;
    double[,] elementX = new double[resolution,resolution];
    double[,] elementY = new double[resolution,resolution];
    double[,] elementZ = new double[resolution,resolution];
    double[,] colorArray = new double[25, 25];
    Random random = new Random();
    /*for( j = 0; j < 25; j ++)
    {
     for( i = 0; i < 25; i++)
     {
      elementX[j,i] = random.Next(1);
      elementY[j,i] = random.Next(1);
      elementZ[j,i] = random.Next(1);
     }
    }*/
    double temp;
    for( j = 0; j < 25; j ++)
    {
     temp = radius * Math.Sin(( j - resolution / 2) * Math.PI / resolution);
     for( i = 0; i < 25; i++)
     {
      elementX[i,j] = radius * Math.Cos( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
      elementY[i,j] = radius * Math.Sin( 2 * Math.PI * i / resolution) * Math.Cos(( j - resolution / 2) * Math.PI / 24);
      elementZ[i,j] = temp;
      colorArray[i,j] = random.Next(1);
     }
    }
    //axCWGraph3D1.Plot3DParametricSurface( elementX, elementY, elementX, null );
    axCWGraph3D1.Plots.RemoveAll();
    //axCWGraph3D1.Plots.Add();
    
    axCWGraph3D1.Plot3DParametricSurface(elementX, elementY, elementZ,colorArray);
    axCWGraph3D1.Plots.Item(1).Style = CW3DGraphLib.CWPlot3DStyles.cwSurfaceLine;
   }

I just pass down the random array to 4th parameter , 3DGraph plots out like attachment picture.

 

How to use 4th parameter in this method "Plot3DParametricSurface"?

********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 3 of 7
(4,388 Views)
The last set of points that overlap with the first set of points were being missed out in the calculations. When you calculated the following value

elementX[i, j] = radius * Math.Cos(2 * Math.PI * i / resolution) * Math.Cos((j - resolution / 2) * Math.PI / (resolution - 1));...

the for loop exited when i = resolution. We need to calculate even when i = resolution (which denotes 360 degrees...rather 360 degrees overlapping with 0 degrees). This would result in a closed sphere. The changes are given below.

int i, j;
int resolution = 25;
double radius = 50;
double[,] elementX = new double[resolution+1, resolution];
double[,] elementY = new double[resolution+1, resolution];
double[,] elementZ = new double[resolution+1, resolution];
double[,] colorArray = new double[resolution+1, resolution];
Random random = new Random();
/*for( j = 0; j < 25; j ++)
{
 for( i = 0; i < 25; i++)
 {
  elementX[j,i] = random.Next(1);
  elementY[j,i] = random.Next(1);
  elementZ[j,i] = random.Next(1);
 }
}*/
double temp;
for (j = 0; j < resolution; j++)
{
    temp = radius * Math.Sin((j - resolution / 2) * Math.PI / resolution);
    for (i = 0; i <= resolution; i++)
    {
        elementX[i, j] = radius * Math.Cos(2 * Math.PI * i / resolution) * Math.Cos((j - resolution / 2) * Math.PI / (resolution - 1));
        elementY[i, j] = radius * Math.Sin(2 * Math.PI * i / resolution) * Math.Cos((j - resolution / 2) * Math.PI / (resolution - 1));
        elementZ[i, j] = temp;
        colorArray[i, j] = random.Next(1);
    }
}
//axCWGraph3D1.Plot3DParametricSurface( elementX, elementY, elementX, null );
axCWGraph3D1.Plots.RemoveAll();
//axCWGraph3D1.Plots.Add();

axCWGraph3D1.Plot3DParametricSurface(elementX, elementY, elementZ, colorArray);
axCWGraph3D1.Plots.Item(1).Style = CW3DGraphLib.CWPlot3DStyles.cwSurfaceLine;
0 Kudos
Message 4 of 7
(4,369 Views)

Hi Sgopal

 

Thanks very much for this, I have fixed it.

********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 5 of 7
(4,335 Views)

Hi Sgopal

When I pass "null" to the 4th parameter of Plot3DParametricSurface(elementX, elementY, elementZ, null); function,

A message " Array dimension mismatch" pop up.

Just pass a double[,] colorArray = new double[25, 25]; to it, it works.

 

why?

********************************
*The best Chinese farmer*
********************************
0 Kudos
Message 6 of 7
(4,332 Views)
I tried doing this in a VS2003 WindowsForms application and I had the same problem. If you do not want the colour information to be available during plotting, you could do the following.

axCWGraph3D1.Plot3DParametricSurface(elementX, elementY, elementZ, Type.Missing);

This will invoke the function that needs only 3 parameters. The interface that VS2003 generated for the ActiveX control does not have the function that takes only 3 arguments.

It would be good if you use the custom C++ interface that we provide (MFC application) because it has been tried and tested by us. This has the Plot3DParametricSurface function that takes only 3 arguments. Hope this helps.
0 Kudos
Message 7 of 7
(4,293 Views)