Patch Normals Algorithm
Asked Answered
I

1

7

I'm trying hard to reproduce a MATLAB algorithm called "patchnormal" which first calculates the normal vectors of all faces, and after that calculates the vertex normals from the face normals weighted by the angles of the faces. (See illustration below)

There doesn't seem to be a free library available for 3D mesh in WPF C# oriented to such mathematical use. Or is there ?

So the question is : How do I compute this (red) vector for all my vertices? Can it be optimized to be used in real time simulation ?

PatchNormal Illustration Image
(source: hostingpics.net)

Indoctrinate answered 17/9, 2012 at 8:44 Comment(0)
A
2

You can compute the angle between two edges as follows:

given:  edge vectors E and F for a given face of your vertex,

E_normalized = normalize(E)
F_normalized = normalize(F)
cross_normal = cross(E_normalized, F_normalized)
sin_theta = length( cross_normal )
cos_theta = dot(E_normalized, F_normalized)

results:
    face normal = normalize(cross_normal)
    face angle theta = atan2(sin_theta, cos_theta)

Then, weight the normals accordingly:

total_vector = vec(0,0,0)
for(each face adjacent to a particular vertex):
    [compute normal and theta as above]
    total_vector += normal * theta
return normalize(total_vector)

To optimize for real-time, I would first profile to see what was actually slowing things down. I'd guess that computing atan2() several times per vertex might turn out to be expensive, but improving on that would really require finding some substitute for angle-weighted normals.

Attlee answered 17/9, 2012 at 19:42 Comment(1)
Hi @Attlee Thank you very much for your answer, this will definitly help me on my project ! CheersIndoctrinate

© 2022 - 2024 — McMap. All rights reserved.