我一直在努力为Javascript找到一个凸壳库,它提供与Matlab convhulln函数相同的输出。
我正在将一些代码从Matlab转录到Javascript,我需要找到构成一组顶点凸包的三角形。 Matlab使用convhulln(利用qhull函数)计算一些3D点的凸包。在这种情况下,当我将相同的顶点传递给每个时,Matlab convhulln将一组不同的三角形面输出到quickhull3d。有些面孔重合但一般大多数都没有。它们唯一的相似之处是它们都输出相同数量的面(尽管面的实际顶点不相同)。
http://www.mathworks.com/help/matlab/ref/convhulln.html
在Javascript中,我尝试过不同的库,每个库都提供不同的输出..
从npm开始,我试过了:
quickhull3d
- https://github.com/maurizzzio/quickhull3d
convex-hull
delaunay-triangulate
大多数其他算法都是针对2D点设计的,所以我已将它们排除在外。
任何想法,提示或反馈将不胜感激!谢谢!
以下是我使用的顶点以及MATLAB的convhulln和quickhull3d的结果。请注意我已经使用排序算法从第一个顶点到最后一个顶点对它们进行排序。这不应该影响实际的三角形面,因为我在MATLAB和JS代码中以完全相同的方式对它们进行了排序。
以下是两个船体的情节。
注意漏洞。我已经与quickhull3d算法的开发人员交谈了(感谢您的回复!!)他建议可能是他使用的三角测量过程与matlab使用的不同。
vertices = [
[ 0.9510565162951535, -0.3090169943749474, 0 ],
[ 0.5877852522924731, -0.8090169943749475, 0 ],
[ 6.123233995736766e-17, -1, 0 ],
[ -0.5591929034707466, 0.8290375725550418, 0 ],
[ -0.9510565162951535, -0.3090169943749475, 0 ],
[ -0.9510565162951536, 0.3090169943749473, 0 ],
[ -0.5877852522924732, 0.8090169943749473, 0 ],
[ -1.8369701987210297e-16, 1, 0 ],
[ 0.5877852522924729, 0.8090169943749476, 0 ],
[ 0.9510565162951535, 0.3090169943749476, 0 ],
[ 0.984807753012208, 0, -0.17364817766693033 ],
[ 0.30432233187297814, -0.9366078308002486, -0.17364817766693033 ],
[ -0.796726208379082, -0.5788554735638644, -0.17364817766693033 ],
[ -0.7967262083790821, 0.5788554735638641, -0.17364817766693033 ],
[ 0.3043223318729779, 0.9366078308002487, -0.17364817766693033 ],
[ 0.5000000000000001, -0.5, 0.7071067811865475 ],
[ -0.5, -0.5000000000000001, 0.7071067811865475 ],
[ -0.5000000000000001, 0.5, 0.7071067811865475 ],
[ 0.4999999999999999, 0.5000000000000001, 0.7071067811865475 ],
[ 6.123233995736766e-17, 0, 1 ]
]
来自quickhull3d的三角形: 昏暗= 36x3
trianglesqh = [
[ 0, 1, 11 ],
[ 0, 9, 18 ],
[ 0, 10, 9 ],
[ 0, 11, 10 ],
[ 0, 15, 1 ],
[ 0, 18, 15 ],
[ 1, 2, 11 ],
[ 1, 15, 2 ],
[ 2, 12, 11 ],
[ 2, 15, 16 ],
[ 2, 16, 12 ],
[ 3, 6, 17 ],
[ 3, 7, 14 ],
[ 3, 13, 6 ],
[ 3, 14, 13 ],
[ 3, 17, 7 ],
[ 4, 5, 13 ],
[ 4, 12, 16 ],
[ 4, 13, 12 ],
[ 4, 16, 17 ],
[ 4, 17, 5 ],
[ 5, 6, 13 ],
[ 5, 17, 6 ],
[ 7, 8, 14 ],
[ 7, 17, 18 ],
[ 7, 18, 8 ],
[ 8, 9, 10 ],
[ 8, 10, 14 ],
[ 8, 18, 9 ],
[ 10, 11, 12 ],
[ 10, 12, 14 ],
[ 12, 13, 14 ],
[ 15, 18, 19 ],
[ 15, 19, 16 ],
[ 16, 19, 17 ],
[ 17, 19, 18 ]
]
来自MATLAB的三角形: 昏暗= 36x3
trianglesm = [
[ 0, 1, 11 ],
[ 0, 9, 18 ],
[ 0, 10, 9 ],
[ 0, 11, 10 ],
[ 0, 15, 1 ],
[ 0, 18, 15 ],
[ 1, 2, 11 ],
[ 1, 18, 2 ],
[ 2, 3, 11 ],
[ 2, 15, 16 ],
[ 2, 16, 3 ],
[ 3, 4, 12 ],
[ 3, 12, 11 ],
[ 3, 16, 4 ],
[ 4, 5, 12 ],
[ 4, 17, 5 ],
[ 5, 8, 13 ],
[ 5, 13, 12 ],
[ 5, 16, 17 ],
[ 5, 17, 6 ],
[ 6, 7, 14 ],
[ 6, 14, 13 ],
[ 6, 17, 7 ],
[ 7, 8, 14 ],
[ 7, 17, 18 ],
[ 7, 18, 8 ],
[ 8, 9, 10 ],
[ 8, 10, 14 ],
[ 8, 18, 9 ],
[ 10, 11, 14 ],
[ 11, 12, 13 ],
[ 11, 13, 14 ],
[ 15, 18, 19 ],
[ 15, 19, 16 ],
[ 16, 19, 17 ],
[ 17, 19, 18 ]
]
答案 0 :(得分:0)
您可以尝试使用Bowyer-Watson算法,但需要使用环绕球和四面体:https://en.m.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm。