C# wpf 3D 面向 Origo
如果我有三个点并且总是希望可见面应该是从原点“面向”的一侧,是否有计算平面法线的快捷方式?
像这样
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
normal = Vector3D(1,1,1);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
model = new GeometryModel3D(mesh, material);
还是我每次都必须计算正常?
如果我必须计算法线,那么算法是什么,我在互联网上查找并尝试了几种方法,但它们让我怀疑,就像这个。
normal = CalculateNormal(p0, p1, p2);
其中CalculateNormal
public static Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
{
Vector3D v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
Vector3D v1 = new Vector3D(p1.X - p2.X, p1.Y - p2.Y, p2.Z - p1.Z);
return Vector3D.CrossProduct(v0, v1);
}
不应该是
Vector3D v1 = new Vector3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z);
反而 ?
/斯特凡
If I have three points and always want the visible face should be the side that is "facing" from origo, is there a shortcut to calculate the normal of the plane ?
Like this
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
normal = Vector3D(1,1,1);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
mesh.Normals.Add(normal);
model = new GeometryModel3D(mesh, material);
Or do I have to calculate the normal every time ?
If I have to calculate the normal, what is the algorithm for that, I have looked on the internet and tried a couple methods but they make me suspicious, like this one.
normal = CalculateNormal(p0, p1, p2);
Where CalculateNormal is
public static Vector3D CalculateNormal(Point3D p0, Point3D p1, Point3D p2)
{
Vector3D v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
Vector3D v1 = new Vector3D(p1.X - p2.X, p1.Y - p2.Y, p2.Z - p1.Z);
return Vector3D.CrossProduct(v0, v1);
}
should it not be
Vector3D v1 = new Vector3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z);
instead ?
/Stefan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的效果很好
The following works well