Writing Code for Surface Plots?
MySchizoBuddy asks: "In what ways can you code plots of surface charts using a z(x,y) function or a cloud of points? I'm looking for a tutorial that explains this that doesn't use DirectX or OpenGL libraries (the language I'm using cannot use either framework anyway). How is the 3D mess generated and how can the 2D contour plots be generated as well? I'm assuming once I know that I can also use it to make torus plots as well. Remember, I'm asking for the explanation of the underlying math and an example code that does that. The GNUPlot gallery has some examples that I find helpful, but are there similar examples out there? (Remember, I am writing the plotting code as well)? Can anyone help or point me in the right direction?"
You could plot graphics that represent levels as colours. I think I invented a kind of R^2->R function plot that represents a Z value as the degree of grey (0 being black, 255 being white) corresponding to Z mod 255. The result is that the more frequent "cuts" (sudden changes from white to black) are, the highest is the derivative.
Looky here, here and here.
just a thought, but why not use MATLAB. You can sometimes use it to make stand-alone programs and maybe even DLLs. then add it to your code. I help develop code for a Cray X1 and all visualization (for my project) is done locally using MATLAB. It's pretty beefy, but it'll make a contour plot.
887321 = 337*2633
I know this doesn't help you, but I'm still curious -- under what circumstances can you not use OpenGL for this? Under what circumstances would it be easier to implement it yourself than to find/create a decent GL binding? Or maybe you could just read the software implementation from Mesa?
Don't thank God, thank a doctor!
dim ymax(screenwidth),ymin(screenwidth)
For xtemp = xlower to xupper step xincr
for ytemp = ylower to yupper step yincr
compute z=f(xtemp,ytemp)
(x,y)=transform(xtemp,ytemp,z)
if yymax(x) then plot x,y : ymax(x) = y
next ytemp, xtemp
Adjust your viewpoint for your 3D to 2D matrix so it plots from front to back.
Algorithm comes from an old book on doing 3D on an Apple ][ - it wasn't too hard to convert it to work on a TRS-80 Model I or a CoCo.
Regarding point #2 and #3, if he's just plotting points to make a graph, fancy perspective may not be needed. Just throw away the Z coordinate after rotation, and plot the X and Y in 2D.
Also, if you're rotating the graph in real-time, don't rotate the points a degree, plot, and rotate another degree and plot, and so on.
Save the original set of points. Rotate them one degree and plot. Throw those results away, start with the original set and rotate them two degrees and plot. Repeat, rotating only the original set each time. You'll save a lot of trouble from accumulating floating point errors.
Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
Generic Mapping Tool, will do everything you want, and a lot you have not even thought of yet. GMT produces postscript and encapsuleated postscript, so if you have a postscript viewer your good to go, runs on unix/linux, is GPL'd so there source code to analyse. There are lots of examples with generating scripts such as time-series collected along a track or a 3D perspective, artificialy illuminated, greyscale image; just reading and understanding the accompanying ducumentation should be good for college credit in cartography.
Apocalypse Cancelled, Sorry, No Ticket Refunds