简体   繁体   English

2D矢量到3D矢量

[英]2D vector to 3D vector

I'm trying to make a circle across a plane using sin and cos. 我正在尝试使用sin和cos在飞机上绕圆。 While it works all well when its aligned with the x, y, or z axis, I need something more dynamic. 当它与x,y或z轴对齐时,虽然一切正常,但我需要更具动态性的东西。 Is there any way to transform a 2D vector to a 3D one using a plane normal, or perhaps another solution? 是否可以使用平面法线或其他解决方案将2D向量转换为3D向量?

您可能想查看MathOverflow。

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? 因此,如果我的问题正确,您想在不直接面对轴之一的3D空间中画一个圆吗? 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). 一种方法是首先使用正常的3D向量作为中心,并以2D方式在其周围绘制一个圆,使其仍然面对轴中的一个(忽略第三个坐标)。 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. 如果您需要进一步了解(旋转)矩阵的工作方式,请在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. 如果要在Java之类的代码语言中使用此方法,则首先需要创建一个类来包含矩阵的数学运算。 I can tell you these if neccessary, as I had a dimension-based problem too once. 我可以告诉您这些是否必要,因为我也曾经有过一个基于维度的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM