This topic is now archived and is closed to further replies.


Metaballs - Normals

Recommended Posts

hi , im implemting a metaballs demo using the marching cubes algorithm, anyway , im wondering how to calculate the normal at each vertex on the polygonized scalar filed... im creating the scalar filed using the function 1/(R^2), while as you guess:

R^2 = x^2 + y^2 + z^2 what i thought about is to find the gradient function of the above one , so what i did is:

f(x,y,z) = 1/(x^2 + y^2 + z^2) (u/v)' = (uv' - u'v)/(v^2) for X: f(x,y,z)' = [-(x^2)' - (y^2)' - (z^2)']/[(x^2 + y^2 + z^2)^2] Y and Z are constants so: f(x,y,z)' = (-2x)/[(x^2 + y^2 + z^2)^2] = -2x / (R^4) we will get the same for Y and Z: for y: -2y / (R^4) for z: -2z / (R^4) so from that i can say the the tangent vector of f(x,y,z) = 1/(x^2 + y^2 + z^2) is: (-2x / (R^4),-2y / (R^4),-2z / (R^4))

the problem is... how do i get the normal vector from the tangent vector at each vertex? Thanks in advance.

Share this post

Link to post
Share on other sites
1) The Vector You calculate by (d/dx)f(x) actually IS the normal Vector. What You are displaying is a surface of equal values f(x)=const while the gradient gives You the direction where f(x) is growing most.

2) I´ve done some experiments with the marching cubes myself. From my experiments it is MUCH better not to calculate the Gradient at each gridpoint.

Since my other option right now would be learning some solid-body physics now, i will take some time going into details ;] ...

The marching cubes algorithm calculates correct values for every gridpoint. Then it checks all the lines connecting adjacent girdpoints. If one edge is above your isolevel (= the value of f(x) corresponding to the surface you want to draw) plus the other edgevalue being lower it assumes, that a point of you surface is lying on that line. The coordinates of that point are detemined by linear interpolation.

Now it would be the first logical step to do the same thing for your normals (=gradients). Calculate the normal at every vertex (perhaps just those you really need, but thats not important here) and do the same linear interpolation. That was my 2nd try (1st try was calculating the normals ith the vector product).

It truns out that while linear interpolation is great (and fast) for getting the coordinates of your point the surface doesnt look good at all. Theres no smooth shading at all. I don´t really know the reason but I found a better way to do it:

Calculate Your normal AFTER you have found a position by linear interpolation. Thus you get a correct normal for a semi-correct point. The improvement is dramatic!

One more thing: If you´re going for the normal and not for the correct gradient You will want to skip the 2* in Your derivative since you want to normalize your normal anyways.

Hope I could help You. Also hope I didn´t write 2 much stupid things You knew anyways but I just recently experimented with the marching cubes so I was quite excited to answer You.

Share this post

Link to post
Share on other sites