Wednesday 15 October 2008

Contour Maps

Random Posts - Cute little function I worked out to plot cool looking contour maps -
Used for Bill Dance's Gone Fishin' Game -

You give four 2D spatial variables - eg. 4 Water temperature values measure over one square metre of a lake.
And then you can use the function to interpolate the temperature at a given point (x,y)
( 0 <= x <= 1) , ( 0 <= y <= 1)

// to-------t1 //
// |aaaaaaaaa| //
//|vvvvvvvvv | //
// t3-------t2 //


//distances are 1 UNIT apart t0,t1,t2,t3 are temperatures // x and y are distances (0-1) x +ve t0-->t1, y +ve t0-->t3
// returns an interpolated value for coordinate x,y
// Produces nice contour maps

float calcTemp(float t0, float t1, float t2, float t3, float x, float y)
{
float xb = (1.0-x) ;
float yb = (1.0-y) ;
return (t0*xb*yb + t1*x*yb + t2*x*y + t3*xb*y) ;
}

2 comments:

lazydog said...

Can you post some Maple code that demonstrates your cute function working?

thanks

your biggest fan - ben

John Wilson said...

Sure Ben! Glad to hear you're my number 1 fan. I'll get back to you buddy.