3D function with ElevationGrid
I have been thinking about 3D graphing using ElevationGrid for a while and finally got time to demonstrate here. Previously, I have blogged about 3D plotting and ElevationGrid, This blog is simply taking the same maths function f(x,z) = x*z^3-z*x^3 in the 3D plotting blog and apply to the ElevationGrid object.
Let's play around this 3D graph first. (Hint: You may press m key to switch rendering from point to line to face)
; 3D function with ElevationGrid By Andy Yeh (2014) ; Functions adapted from: ; http://www.benjoffe.com/code/tools/functions3d/examples CS RESET SETBG 30 ; define the mathematical function to be plotted TO fn :x :z OUTPUT (:x*:z^3-:z*:x^3)/1000 ; output (1 - abs :z) * 3 ; output 2/exp((:x*5)^2*(:y*5)^2) ; output 1 - abs (:x + :z) - abs (:z - :x) ; output -sqrt(:x^2+:z^2) * 10 ; output sin(10*(:x^2+:z^2)) * 20 ; output log10(:x^2+:z^2) ; output sin(45*:x) * cos(45*:z) ; output (:x^3 - :z^2) / 100 END ; start collecting heights MAKE "height [] FOR [ x -10 10 1 ] [ FOR [ z -10 10 1 ] [ MAKE "y fn :x :z QUEUE "height :y ] ] ; start creating FD 10 WEST 10 ELEGRID MAKE "obj WORD OBJECT "_elegrid SET :obj "xdimension 21 SET :obj "zdimension 21 SET :obj "height :height SHOWALL
As can be seen in the Logo program, I have included a few 3D functions for you to try. You can comment out line 8 and uncomment any from line 9-16 to try. Feel free to change the function and enjoy the surprise you get. If any, please share below in the comment area or post your own blog.
In VRMath2 Editor, you can create an ElevationGrid using ELEGRID command. By default, you will get a 10 by 10 grid on X-Z plane with random heights in Y. In line 20 and 21, I used FOR command to create a 21 by 21 grid. The x and z are ranging from -10 to 10 with a step of 1. y was then calculated in line 22 calling to the FN procedure, then QUEUE into the height list in line 23.
Because of the grid height collected is 21x21, therefore, line 29-30 changed the default 10x10 grid to 21x21 and set height to the collected height list.
Please leave a comment below if you found other interesting 3D functions. And I wish to acknowledge the functions borrowed/adapted from Ben Joffe's function3d example page, thanks.
- Andy's blog
- Login or register to post comments
- 4921 reads