• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Interpolation of four points (grid corners)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1JohnnyLightwave  Members

Posted 18 February 2013 - 01:01 PM

Hi all,

Consider, if you will, this image:

http://i.imgur.com/xsZ6duv.png

Assuming that the four corners there have n value, I'm looking for a way to determine the best values for the red dots (or, actually, and point within the square).  I'm trying to determine light values at a finer grain than just finding the nearest corner and using it.

Is there a way to do this?  I tried simple linear interpolation combining both directions, but the results aren't satisfactory, so I think the way I thought up is fatally flawed.

Thanks for any help!

--JR

### #2C0lumbo  Members

Posted 18 February 2013 - 01:08 PM

I usually do something like interpolate between the TL and TR values according to the X position to get a Top value, then interpolate between the BL and BR values according to the X position to get a Bottom value, then interpolate between my calculated Top value and my calculated Bottom value according to the Y position to get a final result.

Not sure if there's better options out there.

### #3JohnnyLightwave  Members

Posted 18 February 2013 - 01:10 PM

Do you happen to have a scrap of code I can look at?  Cuz I'm doing something similar to that, I think-- I'm getting a left right value, and then modulating it against an up-down value.  Like I said, the results are... much worse than I would have expected, so I'm clearly doing something wrong.

### #4godmodder  Members

Posted 18 February 2013 - 01:27 PM

Have you tried looking into Bilinear interpolation?

### #5C0lumbo  Members

Posted 18 February 2013 - 01:29 PM

Do you happen to have a scrap of code I can look at?  Cuz I'm doing something similar to that, I think-- I'm getting a left right value, and then modulating it against an up-down value.  Like I said, the results are... much worse than I would have expected, so I'm clearly doing something wrong.

Here's some code from my perlin noise code. It uses a cosine interpolation for extra smoothness in ground height, but a straight lerp should work OK too.

	// Separate the base and the fraction parts.
int iBaseX = (int)floorf(vInput.GetX());
float fFractionX = vInput.GetX() - (float)iBaseX;
int iBaseY = (int)floorf(vInput.GetY());
float fFractionY = vInput.GetY() - (float)iBaseY;

// Cosine interpolation
float fTL = GetDiscreteNoise2D(iBaseX, iBaseY, pPrimeSet);
float fTR = GetDiscreteNoise2D(iBaseX + 1, iBaseY, pPrimeSet);
float fBL = GetDiscreteNoise2D(iBaseX, iBaseY + 1, pPrimeSet);
float fBR = GetDiscreteNoise2D(iBaseX + 1, iBaseY + 1, pPrimeSet);
float fT = CosInterp(fTL, fTR, fFractionX);
float fB = CosInterp(fBL, fBR, fFractionX);
float fRet = CosInterp(fT, fB, fFractionY);
return fRet;



Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.