# Numerical Integration over 3D mesh

1. Apr 27, 2013

### thepopasmurf

Hi, I have a mesh whose surface is made up of tesselating triangles. I would like to perform an integral over this surface of the form

$\int f(\Omega) R(\Omega) d\Omega$

Where f is an arbitrary function and R is the radius at that point.

I have a method implemented but it is not working correctly. I was wondering if anyone was aware of a better way.

Basically my method is

For each triangular face:

1. Calculate the value of fR at each vertex of the face
2. Calculate the average of these three values to find the average value of fR across the face.
3. Multiply this value by the solid angle covered by the face.
4. Sum up this result for all of the faces in the mesh.

Unfortunately it doesn't seem to be working as I would have liked. Are there recommended ways of doing this kind of integration?

(This is x-posted in another forum for those who may happend to see both)

Thanks.

2. Apr 27, 2013

### SteamKing

Staff Emeritus
I think you need to consult with Messrs. Green and Gauss on this point,and possibly Mr. Stokes as well. Their integral theorems for vector calculus can provide the requisite tools to evaluate your integral.

It's not clear from your description what R(Omega) and the variable Omega represent.

3. Apr 28, 2013

### thepopasmurf

Omega is the solid angle and d(Omega) is solid angle differential element

$d\Omega = sin\theta d\theta d\phi$

Although I'm not computing it based on that equation, I'm computing it from the solid angle covered by the triangular element in question using the formula:

$E = (A+B+C) - \pi$

Where A,B,C are angles of the spherical triangle with the same vertices as the triangle element.

References:

http://en.wikipedia.org/wiki/Solid_angle
http://mathworld.wolfram.com/SphericalTriangle.html

4. Apr 28, 2013

### Office_Shredder

Staff Emeritus
In your integral you wrote $f(\Omega) R(\Omega)$ which is weird because $\Omega$ isn't actually representing coordinates - is it supposed to be spherical coordinates? And you're projecting out to the mesh or something?

I think a bit more specific description of your integral might help - it's possible that you've forgotten a change of variable Jacobian without realizing it by attempting to write your integral down in a clever way

5. Apr 28, 2013

### Solkar

Hi thepopasmurf!

Let N be the number of facets of your tess.

You want to approximate
$$\int f(\Omega) R(\Omega) d\Omega \approx \frac{1}{3} \sum\limits_{i=1}^{N}{A(S_i) \sum\limits_{j=1}^{3}{f(v_j[S_i])R(v_j[S_i]) }}$$
with $$A(S_i)$$ denoting the area covered by the i-th Facet and $$v_j[S_i]$$ its j-th vertex?

That ansatz looks accurate at a first glance, except I'm not sure
you did this one accurately; you're aware that the area of the $$S_i$$ in general depends on the embedding of the surface into the ℝ³, don`t you?

Generally - what is the symptom of the failure you diagnose?

Regards, Solkar

6. Apr 28, 2013

### Solkar

But not on a second glance, because

it's not R but R² needed.

Thus, there's also a numerical issue, because simply taking the arithmetic mean of the radii of the adjacent vertices can cause a bad estimation.

7. Apr 28, 2013

### thepopasmurf

@Office_Shredder:

The specific integral I am trying to do is the spherical harmonic integrals,

$a_{vm} = A \int Y_{vm}(\theta, \phi) R(\theta,\phi) sin \theta d\theta d\phi$

where Y_vm are the spherical harmonic functions and A is a normalisation constant. I used Omega to represent both theta and phi but apparently that convention is not as common as I thought.

@Solkar

See my reply to Office_Shredder above, I'm fairly sure it's just R. The symptom of the failure I'm having is that when I try to reconstruct shapes after getting the coefficients there are large errors.

8. Apr 28, 2013

### Solkar

Then integrate analytically with f = 1 and R = const and reconsider.

9. Apr 29, 2013

### thepopasmurf

The purpose of the integral is not to find the area, but to find the harmonic coefficients of R.

10. Apr 29, 2013

### Solkar

But for your numerical integration you need the correct area element.

11. Apr 29, 2013

### thepopasmurf

Last edited by a moderator: May 6, 2017
12. Apr 29, 2013

### Solkar

That's on a unit sphere so R=R²=1.

13. Apr 29, 2013

### thepopasmurf

I think it's fine that it's on a unit sphere because the distance part is accounted for in the integrand. And I'm not sure why I would have to add an extra R just because the function is the radius rather than any other function.

Anyway, I think we're getting distracted by this point. I'm ultimately trying to solve this integral as an integral over theta and phi where the values of theta and phi available to me are from a mesh.

If you think I should be using R^2 instead of R could you provide more details as to how I would proceed with that change. One issue I have with this point is that the units change.

14. Apr 30, 2013

### Solkar

It's not question of "thinking" things, but about knowing Lebesgue measure and the foundations of differential geometry.

For your numerics It is advisable to discard the smooth approach for calculating area and simply calculate the area of each triangular facet of your mesh; recall what you learned about cross products for that purpose.

15. Apr 30, 2013

### thepopasmurf

So should I change my integrand from

$\int Y R d\Omega$

to

$\int \frac{Y}{R} dA$

to keep the units correct?

16. Apr 30, 2013

### Solkar

It's somewhat amazing that people looking for help don't even read the answers given, let alone trying them

and you tried to numerically integrate a function on that by means of generalized Riemann partitioning.

So what by all means should be unclear when I tell you to calculate the area of the tris of your tesselation?
It's a most natural requisite for your integration algorithm, isn't it?

17. Apr 30, 2013

### thepopasmurf

I'm sorry that this is frustrating for you, but I'm not yet convinced that the area of the triangles is exactly what I want. I'll try to explain my approach in more detail.

I have a mesh of an object made up of triangular faces. I'm trying to get the spherical harmonics components of the mesh

$a_{mn} = \int Y R d\Omega$

I'm approximating this as

$a_{mn} = \sum Y_{mn} R_{mn} \Delta\Omega$

Where Delta Omega is a small part of the solid angle. I know that the area is related to this, but this specific integral doesn't seem to require knowing the area directly of the triangular face, it requires knowing how much solid angle it covers.

You could be right, but calculating the area of each triangle isn't useful to me directly. One problem is that the integrand has to be altered to keep the units consistant. So are you also suggesting a change of the integrand when you suggest that I use the area of the triangles?

18. May 1, 2013

### Solkar

And I'm not yet convinced that you have any clue to what you try to do.
So first better you try to convince me that you're not wasting my time here.

Last edited: May 1, 2013