Re: [Algorithms] Tangential Curvature of terrain
Brought to you by:
vexxed72
From: Thatcher U. <tu...@tu...> - 2000-08-21 15:40:52
|
From: Joe Ante <jo...@ti...> > Thatcher wrote: > > 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. Whoops, you're right, I made a totally bogus statement. The curvature of a function is actually much more than just the second derivative. According to my calc book it's: for a parametric curve with x = f(t), y = g(t): k = | x'y'' - y'x'' | / ((x'^2 + y'^2) ^ (3/2)) I'm not sure that corrected definition impacts the original problem or its solution much. > 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. That will give a nice smoothed scalar field, but it loses the directionality of the tangent/profile curvature that I think Klaus was looking for. If I read Ron correctly then you're computing something similar to the "mean curvature", although not exactly the same thing because you're averaging over all directions and across a potentially large area. But it's probably still useful for ecosystem stuff. -- Thatcher Ulrich http://tulrich.com |