2D 矢量转 3D 矢量

发布于 2024-08-12 12:07:53 字数 110 浏览 1 评论 0原文

我正在尝试使用 sin 和 cos 在平面上画一个圆。虽然它在与 x、y 或 z 轴对齐时工作得很好,但我需要更动态的东西。有没有办法使用平面法线将 2D 矢量转换为 3D 矢量,或者可能是另一种解决方案?

I'm trying to make a circle across a plane using sin and cos. While it works all well when its aligned with the x, y, or z axis, I need something more dynamic. Is there any way to transform a 2D vector to a 3D one using a plane normal, or perhaps another solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天生の放荡 2024-08-19 12:07:53

您可能想查看MathOverflow。

You might want to check out MathOverflow.

拒绝两难 2024-08-19 12:07:53

那么,如果我的问题正确的话,您想在 3D 空间中画一个不直接面向其中一个轴的圆吗?一种方法是首先使用法线 3D 向量作为中心,并围绕它以 2D 方式画一个圆,因此它仍然面向其中一个轴(忽略第三个坐标)。要旋转圆,您需要使用旋转矩阵并将它们应用于生成圆的点。其数学原理是:(

raw_point = Center + ( cos(angle)|sin(angle) )

          [raw_point.x]   [1][0             ][0              ]   [cos(YRotation)][0][-sin(YRotation)]   [cos(ZRotation)][-sin(ZRotation)][0]
3DPoint = [raw_point.y] * [0][cos(XRotation)][-sin(XRotation)] * [0             ][1][0              ] * [sin(ZRotation)][cos(ZRotation) ][0]
          [raw_point.z]   [0][sin(XRotation)][cos(XRotation) ]   [sin(YRotation)][0][cos(YRotation) ]   [0             ][0              ][1]

括号块是矩阵)

如果您需要进一步解释(旋转)矩阵的工作方式,请在维基百科上查找。
顺便提一句。如果您想在像 java 这样的代码语言中使用此方法,您首先需要创建一个类来包含矩阵的数学运算。如果有必要,我可以告诉你这些,因为我也曾经遇到过基于维度的问题。

So, if I got your question right, you want to draw a circle in 3D space which is not facing one of the axis directly? A way to do so would be to first use a normal 3D vector as center and draw a circle in a 2D manner around it, so it still faces one of the axis(ignoring the third coordinate). To get the circle rotated you need to use rotation matrixes and apply them to the points that generate the circle. the mathematics for this would be:

raw_point = Center + ( cos(angle)|sin(angle) )

          [raw_point.x]   [1][0             ][0              ]   [cos(YRotation)][0][-sin(YRotation)]   [cos(ZRotation)][-sin(ZRotation)][0]
3DPoint = [raw_point.y] * [0][cos(XRotation)][-sin(XRotation)] * [0             ][1][0              ] * [sin(ZRotation)][cos(ZRotation) ][0]
          [raw_point.z]   [0][sin(XRotation)][cos(XRotation) ]   [sin(YRotation)][0][cos(YRotation) ]   [0             ][0              ][1]

(The bracket blocks are matrixes)

If you need further explanation of the way (rotation-)matrixes work look it up on wikipedia.
Btw. if you want to use this method in a code language like java you first need to create a class to contain the mathematics of the matrixes. I can tell you these if neccessary, as I had a dimension-based problem too once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文