Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 3d Graph plotting

Discussion in 'General Graphics' started by DamianoP, Dec 18, 2019.

  1. DamianoP

    DamianoP

    Joined:
    Apr 5, 2016
    Posts:
    6
    Hi all,
    i want to plot a 3d Graph, for example:
    f(y)= x^2 - z^2 + 1;
    Here is my result:




    Here is a portion of my script:
    Code (CSharp):
    1.  
    2. for (int i = 0; i < 50; i++)
    3.             for (int j = 0; j < 50; j++) {
    4.                 Transform point = Instantiate(pointPrefab); // a sphere
    5.                 position.x =    (i + 0.5f) * step - 1f;
    6.                 position.z =    (j + 0.5f) * step - 1f;
    7.                 position.y =    position.x*position.x - position.z*position.z +1;
    8.                 point.localPosition = position;
    9.                 point.localScale = scale/2;
    10.                 point.SetParent(transform, false);
    11.             }
    12.  
    However I do not like the result, I would like to join the points in a mesh so as to display a surface and not a set of balls.
    How can I do that?
     
    Last edited: Dec 19, 2019
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Perhaps research “marching cubes”, for arbitrary mesh generation from a set of points.

    Alternatively, if you know it's always going to essentially be a heightmap, you could generate vertices and indices to represent the surface and apply it to a mesh. (i.e. 2 triangles on the mesh are formed from the verts [x,y] [x+1,y] [x,y+1] and [x+1,y+1] [x+1,y] [x, y+1]
     
    Last edited: Dec 19, 2019
    DamianoP and karl_jones like this.
  3. DamianoP

    DamianoP

    Joined:
    Apr 5, 2016
    Posts:
    6
    Ty very much....I used the second method...and it worked very well.
     
    richardkettlewell likes this.
  4. dashagireevann

    dashagireevann

    Joined:
    Feb 1, 2023
    Posts:
    1
    Hi Damiano, I am Dasha , I like to learn more about 3d plotting .
    Can you send me your full scripts of this 3d plotting , it will be more helpful

    Here is my gmail id - dashagireevann@gmail.com