Re: [Algorithms] Tangential Curvature of terrain
Brought to you by:
vexxed72
From: Joe A. <jo...@ti...> - 2000-08-21 13:19:07
|
> Basically, the curvature of a function is its second derivative. I think geometrically viewn this is not the correct answer. Take as an simplyfied example: f(x) = x^2 f''(x) = 2 Which meant that for every point the concavity/convexity is the same over the entire graph. What this concavity/convexity value actually specifies is how high a heixel is in respect to the heixels in some distance around it. Maybe even in respect to all heightsamples in the heightmap. Consider for example an huge crater landscape and in the middle of this crater there is a small hill. The question now is, is the heixel on top of this small hill inside the huge crater, more convex or concave? So what you want is that heixels that are near have more influence than heixels that are far away from the heixel, whose concavity/convexity you want to find out. So what you need to define is a function with a maximum distance, which gives you out a value between 0...1 when you give it a value from 0...maximumdistance. y = f (x) x e [0...maximumDistance] y e [0...1] A gauss-like curve is propably best suited: y = 360^-((x/maximumDistance)^5) (This function has worked out for me just fine.) Pseudocode: float ConcaveConvex (long inX, long inZ, float inMaxDistance) { float itsHeight = GetHeight (inX, inZ); float c = 0; for (z=0;z<HowmanyHeixels;z++) { for (z=0;z<HowmanyHeixels;z++) { float difference = itsHeight - GetHeight (x, z); float d = sqrt ((x-inX)*(x-inX) + (z-inZ)*(z-inZ)); c += difference * GaussFunction (d, inMaxDistance); } } c /= HowmanyHeixels* HowmanyHeixels; return c; } float GaussFunction (float inX, float inMax) { return powf (360.0F, -powf (inX / (inMax), 5.0F) } float GetHeight () should give back a height scaled to [0...1] in this context. There is plenty room for optimization here (tables, tables, tables) But even then it will be very slow. But it doesnt matter that much because you dont want to calculate the ecomap in realtime or as a preprocessing phase step anyways. Note that I havent integrated this into my terrain engine yet, I have only spent some thought on it, so I cant really guarentee that it works. bye joe |