补丁法线算法

Raz*_*u3D 7 c# 3d wpf patch normals

我正在努力重现一个名为"patchnormal"MATLAB算法,算法首先计算所有面的法向量,然后计算面部法线加权的面法线的顶点法线.(见下图)

似乎没有一个免费的库可用于面向这种数学用途的WPF C#中的3D网格.还是有吗?

所以问题是: 我如何计算所有顶点的这个(红色)矢量?它可以优化用于实时模拟吗?

PatchNormal插图图片http://img15.hostingpics.net/pics/820428PatchNormals.png

com*_*orm 2

您可以按如下方式计算两条边之间的角度:

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)
Run Code Online (Sandbox Code Playgroud)

然后,相应地对法线进行加权:

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)
Run Code Online (Sandbox Code Playgroud)

为了实时优化,我首先会进行分析,看看到底是什么导致速度变慢。我猜想atan2()每个顶点计算几次可能会很昂贵,但对此进行改进确实需要找到角度加权法线的替代品。