3D chart with Mesh surface


https://www.nevron.com/Forum/Topic11830.aspx
Print Topic | Close Window

By mouloud djamah - 8 Years Ago
Using 3d chart with mesh surface, can I generate graphics like these : https://www.nevron.com/forum/uploads/images/a0caf7c0-b798-484f-8ac7-e7f1.png 
By Nevron Support - 8 Years Ago

Hi Mouloud,

Yes - you can generate the attached images with the mesh surface series.

By mouloud djamah - 8 Years Ago
It is easy to make mesh surface (with NChartConrol component) from the data (x, y and z values). But here we have shapes (cylinder and more complicate shapes) . Are there a predefined functions that allow generating the data (x, y, z values) associated to the specific shape (for example cylinder). In general are there (in nevron) a tools or functions that make easy generating graphics like these.    
By Nevron Support - 8 Years Ago
Hi Mouloud,

In general Nevron Chart is not a 3D modelling software so it does not have predefined methods to get the xyz mesh of shapes. We can send you code for the generation of simple shapes (cylinder, cone, torus etc.) if you wish.
By mouloud djamah - 8 Years Ago
Yes send me the code
Thanks
By Nevron Support - 8 Years Ago
Hi Mouloud,

The following code shows how to generate the vertices of a cylinder for example:

  internal static void CreateCylinderY(GLDevice device, NSurface surface, int m, int n, float radiusX, float radiusZ, float minY, float maxY, float cx, float cz)
  {
   float angleStep = (float)(NMath.PI2 / (m - 1));
   NVector3DF v3 = NVector3DF.Zero;
   NVector4DF[] arrPrecomputedData = device.RequestPrecompData4F(m);

   int vertexCount = m * n;

   NVertex.P3N[] vertices = device.RequestBufferP3N(vertexCount);

   int lastM = m - 1;

   for (int i = 0; i < lastM; i++)
   {
    // calculate the current angle, its cos and sin
    float alpha = i * angleStep;
    double cosA = Math.Cos(alpha);
    double sinA = Math.Sin(alpha);

    // this is needed for the normal calculation
    double nx = radiusZ * cosA;
    double nz = radiusX * sinA;
    double len = Math.Sqrt(nx * nx + nz * nz);

    // calculate position
    arrPrecomputedData[i].X = (float)(radiusX * cosA);
    arrPrecomputedData[i].Y = (float)(radiusZ * sinA);

    // normalize the normal vector
    if (len > 0.00001)
    {
     arrPrecomputedData[i].Z = (float)(nx / len);
     arrPrecomputedData[i].W = (float)(nz / len);
    }
    else
    {
     arrPrecomputedData[i].Z = (float)cosA;
     arrPrecomputedData[i].W = (float)sinA;
    }
   }

   arrPrecomputedData[lastM] = arrPrecomputedData[0];

   float sizeY = maxY - minY;
   float cellSizeY = sizeY / (n - 1);
   int vertexIndex = 0;

   for (int j = 0; j < n; j++)
   {
    float y = minY + j * cellSizeY;

    for (int i = 0; i < m; i++)
    {
     // set normal
     v3.X = arrPrecomputedData[i].Z;
     v3.Y = 0;
     v3.Z = arrPrecomputedData[i].W;
     vertices[vertexIndex].N = v3;

     // set position
     v3.X = cx + arrPrecomputedData[i].X;
     v3.Y = y;
     v3.Z = cz + arrPrecomputedData[i].Y;
     vertices[vertexIndex].P = v3;

     vertexIndex++;
    }
   }