Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


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.

  • You cannot reply to this topic
4 replies to this topic

#1 JohnnyLightwave   Members   -  Reputation: 142

Like
0Likes
Like

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

 



Sponsor:

#2 C0lumbo   Crossbones+   -  Reputation: 2386

Like
0Likes
Like

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.



#3 JohnnyLightwave   Members   -  Reputation: 142

Like
0Likes
Like

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.



#4 godmodder   Members   -  Reputation: 705

Like
0Likes
Like

Posted 18 February 2013 - 01:27 PM

Have you tried looking into Bilinear interpolation?



#5 C0lumbo   Crossbones+   -  Reputation: 2386

Like
0Likes
Like

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.



PARTNERS