获取 3D 对象的方向并将其与 WPF 中的 Vector3D 平行对齐
我有一个 WPF 项目,其中导入了表示在 3D Max Studio 中创建的 3D 场景的代码,然后使用工具将其转换为可以在 WPF 中使用的 XAML 代码。
因此,我有一个 Viewport3D,里面有一个代表矩形棱柱的 GeometryModel3D 对象。我有两个 3D 点(X、Y、Z),分别代表向量的起点和终点。
我想做的只是沿着棱镜的最长边将棱镜与我的 Vector3D 平行对齐。我了解一些有关代码中 3D 对象的转换和平移的知识,并且我有一些数学知识,我最大的问题是获取 3D 对象的方向。
我希望能够以某种方式确定物体的向上向量,因为我认为它可以帮助我,而且我还希望能够以某种方式确定棱镜底部和顶部的坐标,所以我可以计算棱镜的“方向”矢量。
我已经在网上呆了几天试图解决这个问题,但我真的很困惑,拜托,任何帮助将非常感激。
谢谢!
I have a WPF project in which I have imported code that represents a 3D scene created in 3D Max Studio and then converted using a tool to XAML code that I can use in WPF.
So, I have a Viewport3D and inside it a GeometryModel3D object that represents a rectangular prism. I have two 3D points (X, Y, Z) that represent the beginning and the end of my vector.
What I would like to do is just align the prism parallel to my Vector3D along the prism's longest side. I know a few things about transformations and translations of 3D objects in code and I have some knowledge in math, my biggest problem is getting the orientation of a 3D object.
I would like somehow to be able to determine the up vector of the object because I think that it could help me, and what I would also like is to somehow be able to determine the coordinates of the base and the top of the prism, so I could calculate the prism's "direction" vector.
I've been on the web for a few days trying to figure this out but I'm really stuck, please, any help would be very much appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上不知道有关 WPF 的代码。但我认为这是一个数学问题。
您可以构造向量的局部矩阵。也就是说,使用要对齐的向量作为Z向量,并找到另一个向量(通常是平行于棱镜底面的向量)作为X,然后对Z,X进行叉积,然后得到Y 。
最后矩阵是M=[X,Y,Z] 如果你想要仿射矩阵,获取棱镜的位置向量,将其设置为T,那么
使用该矩阵的矩阵将是M=[X,Y,Z,T],变换你的棱镜的顶点:v=Mv
I do not know the code about the WPF actually. But I think it is a math problem.
You can construct the local matrix for a vector. That is, using the vector you want to align as Z vector, and find another vector(which is usually a vector parallel to your prism's bottom side) as X, after that do a cross product of Z,X, then you get the Y.
Finally the matrix is M=[X,Y,Z]. If you want affine matrix, get the position vector of prism, set it as T, then the matrix will be M=[X,Y,Z,T]
using this matrix, transform your prism's vertices: v=Mv