A 3D plot of a function of x and y

59 views
Skip to first unread message

Bruce Sherwood

unread,
Jul 10, 2016, 12:39:35 AM7/10/16
to Glowscript Users
Here is a 3D plot of a function of x and y:


It is implemented by creating a 50 by 50 grid of vertex objects whose normals are the averages to the 3D surface in the immediate neighborhood. Then quad objects are created based on these vertex objects.

I'm not proud of the rather clumsy code used to deal with creating normals for vertex objects that are located at the edges of the grid. If you see a better way to do this, I would happily replace that code with yours.

Bruce Sherwood

unread,
Jul 11, 2016, 12:40:08 PM7/11/16
to Glowscript Users
Take another look at


It has been updated to plot a function of x, y, and t, so the surface changes with time.

Bruce Sherwood

unread,
Jul 12, 2016, 12:25:30 AM7/12/16
to Glowscript Users
I simplified my 3D plotting program:


If you "Edit this program" you'll see much shorter code. What I've done is alarmingly obvious, so obvious that it took many days to think of it.

For a 50 by 50 mesh of vertex objects (used to make quads), I make an extra set to the right of the mesh and just above the mesh. These extra vertex objects hold position information but don't appear in any quads. Starting at the lower left corner of the mesh, I make a quad whose lower left corner is the first vertex in the vertex list. That vertex gets a normal that is the cross product of the vector displacement to the right and the vector displacement upwards in the 2D mesh. The last vertex objects on the right or at the top of the mesh calculate these displacements using position information in the extra vertex objects described above. The result is that there are no longer any special edge tests that cluttered the previous version. Duh.

Reply all
Reply to author
Forward
0 new messages