重心计算有何用途?
我一直在研究 XNA 的重心方法,网上找到的描述对我来说相当不透明。举个例子就好了。只要有英文解释就太好了...目的是什么以及如何使用它?
I've been looking at XNA's Barycentric method and the descriptions I find online are pretty opaque to me. An example would be nice. Just an explanation in English would be great... what is the purpose and how could it be used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自维基百科:
我相信它们用于游戏开发中的光线追踪。
当光线与普通网格中的三角形相交时,您只需将其记录为命中或未命中。但是,如果您想实现一个subsurf修改器(下图),这使得网格更加平滑,您将需要光线到达三角形中心的距离(这更容易在重心坐标)。
Subsurf 修改器并不难想象:
立方体是原始形状,内部的平滑网格是“ subsurfed”立方体,我认为递归深度为三或四。
事实上,这可能不正确。不要相信我的确切说法,但我确实知道它们用于几何形状上的纹理映射。
您可以查看以下几张幻灯片: http ://www8.cs.umu.se/kurser/TDBC07/HT04/handouts/HO-lecture11.pdf
From Wikipedia:
They are used, I believe, for raytracing in game development.
When a ray intersects a triangle in a normal mesh, you just record it as either a hit or a miss. But if you want to implement a subsurf modifier (image below), which makes meshes much smoother, you will need the distance the ray hit from the center of the triangle (which is much easier to work with in Barycentric coordinates).
Subsurf modifiers are not that hard to visualize:
The cube is the original shape, and the smooth mesh inside is the "subsurfed" cube, I think with a recursion depth of three or four.
Actually, that might not be correct. Don't take my exact word for it, but I do know that they are used for texture mapping on geometric shapes.
Here's a little set of slides you can look at: http://www8.cs.umu.se/kurser/TDBC07/HT04/handouts/HO-lecture11.pdf
实际上,点 P 相对于三角形 ABC 的重心坐标就是其根据三角形顶点的权重 (u,v,w),使得 P = u*A + v*B + w*C。如果该点位于三角形内,则在 [0,1] 中得到 u,v,w,并且 u+v+w = 1。
它们可用于涉及了解点相对于三角形顶点的位置的任何任务,例如在三角形上插值属性。例如,在光线追踪中,您在三角形内有一个生命点。当您想知道该点的法线或其他属性时,您可以计算其在三角形内的重心坐标。然后,您可以使用这些权重来总结三角形顶点的属性,并获得插值属性。
要计算三角形
ABC
内点P
的重心坐标 (u,v,w
),您可以使用:其中
[ ABC]
表示三角形ABC
的面积。In practice the barycentric coordinates of a point P in respect of a triangle ABC are just its weights (u,v,w) according to the triangle's vertices, such that P = u*A + v*B + w*C. If the point lies within the triangle, you got u,v,w in [0,1] and u+v+w = 1.
They are used for any task involving knowledge of a point's location in respect to the vertices of a triangle, like e.g. interpolation of attributes across a triangle. For example in raytracing you got a hitpoint inside the triangle. When you want to know that point's normal or other attributes, you compute its barycentric coordinates within the triangle. Then you can use these weights to sum up the attributes of the triangle's vertices and you got the interpolated attribute.
To compute a point
P
's barycentric coordinates (u,v,w
) within a triangleABC
you can use:where
[ABC]
denotes the area of the triangleABC
.