We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Surface Visualisation
Page Index Toggle Pages: 1
Surface Visualisation (Read 924 times)
Surface Visualisation
Dec 22nd, 2009, 12:46am
 
I need to visualize a 2D (topographical) surface. ie I have a 2D array where the values represent the height of the surface at that x,y coordinate.
Interpolation and lighting effects would be nice...

Can anyone suggest a suitable starting point/example?
Re: Surface Visualisation
Reply #1 - Dec 22nd, 2009, 2:43am
 
This is the best I could come up with, but I think there might be better ways of doing it.

Code:

float[][] data = new float[100][100];

void setup()
{
 size(1024, 768, P3D);

 for(int i = 0; i < data.length; i++)
 {
   for(int j = 0; j < data[i].length; j++)
   {
     data[i][j] = 100*sin(i/10.0)+100*cos(j/10.0);
   }
 }
}

void draw()
{
 background(0);
 lights();

 beginCamera();
 camera(0, -500, 1500, 0, 0, 0, 0, 1, 0);  
 endCamera();

 noStroke();
 fill(255);

 pushMatrix();
 rotateY(millis()/10000.0);
 translate(-500, 0, -500);
 scale(10, 1, 10);
 
 for(int i = 1; i < data.length; i++)
 {
   for(int j = 1; j < data[i].length; j++)
   {
     beginShape();
     vertex(i, data[i][j], j);
     vertex(i, data[i][j-1], j-1);
     vertex(i-1, data[i-1][j-1], j-1);
     vertex(i-1, data[i-1][j], j);
     endShape();      
   }
 }  
 popMatrix();
}

Re: Surface Visualisation
Reply #2 - Dec 22nd, 2009, 5:26am
 
Thanks JR - impressive.

I have used some fairly sophisticated (and complicated) packages in the past including Mathematica and IDL but I am continuously amazed at the elegant simplicity behind the design of Processing.

I can certainly build on your example.
Re: Surface Visualisation
Reply #3 - Dec 28th, 2009, 4:05pm
 
I like this piece of code. It has a of potential.
Page Index Toggle Pages: 1