从 3d 中的起点和角度计算直线
我在 3D 空间中有一个点和两个角度,我想根据此信息计算结果线。我已经找到了如何使用 2D 线条(但不是 3D)来做到这一点。这怎么计算呢?
如果有帮助:我正在使用 C++ & OpenGL并具有用户鼠标单击的位置和相机的角度,我想追踪这条线的交叉点。
I have a point in 3D space and two angles, I want to calculate the resulting line from this information. I have found how to do this with 2D lines, but not 3D. How can this be calculated?
If it helps: I'm using C++ & OpenGL and have the location of the user's mouse click and the angle of the camera, I want to trace this line for intersections.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在三角术语中,需要两个角和一个点才能在 3d 空间中定义一条线。将其转换为 (x,y,z) 只是极坐标到笛卡尔坐标,方程为:
x = r sin(q) cos(f)
y = r sin(q) sin(f)
z = r cos(q)
其中r为点P到原点的距离; OP 线与正极轴(可以视为 z 轴)之间的角度 q(天顶);以及初始光线与 OP 在赤道平面上的投影之间的角度 f(方位角)(通常从 x 轴测量)。
编辑:
好的,这是你问的第一部分。其余部分,即问题更新后的真正问题,比仅从 2 个角度创建一条线和 3d 空间中的一个点要复杂得多。这涉及到使用相机到世界的变换矩阵,并在其他 SO 问题中进行了介绍。为了方便起见,这里有一个:如何将世界坐标转换为相机坐标? 答案涵盖从世界到相机和相机到世界的转换。
In trig terms two angles and a point are required to define a line in 3d space. Converting that to (x,y,z) is just polar coordinates to cartesian coordinates the equations are:
x = r sin(q) cos(f)
y = r sin(q) sin(f)
z = r cos(q)
Where r is the distance from the point P to the origin; the angle q (zenith) between the line OP and the positive polar axis (can be thought of as the z-axis); and the angle f (azimuth) between the initial ray and the projection of OP onto the equatorial plane(usually measured from the x-axis).
Edit:
Okay that was the first part of what you ask. The rest of it, the real question after the updates to the question, is much more complicated than just creating a line from 2 angles and a point in 3d space. This involves using a camera-to-world transformation matrix and was covered in other SO questions. For convenience here's one: How does one convert world coordinates to camera coordinates? The answers cover converting from world-to-camera and camera-to-world.
这条线可以理解为“时间”中的一个点。该方程必须矢量化,或者有一个方向才有意义,因此时间是一种自然的思考方式。因此,3 维直线方程实际上可能是与时间相关的 x、y、z 的三个二维方程,例如:
要找到该组方程,假设相机位于原点,(0,0,0) ,而你的点是 (x1,y1,z1) 那么
注意
:这还假设线或向量的“速度”是这样的,即 1 秒后它到达你的点 (x1,y1,z1)。
因此,要绘制这条线,只需在需要的时间内尽可能细地填充点,例如每 1/1000 秒持续 10 秒或类似的东西,可能会绘制一条“线”,实际上是一系列点,当从远处看显示为一条线,超过 10 秒的距离,由您选择的“速度”决定。
The line can be fathomed as a point in "time". The equation must be vectorized, or have a direction to make sense, so time is a natural way to think of it. So an equation of a line in 3 dimensions could really be three two dimensional equations of x,y,z related to time, such as:
To find that set of equations, assuming the camera is at origin, (0,0,0), and your point is (x1,y1,z1) then
so
Note: this also assumes that the "speed" of the line or vector is such that it is at your point (x1,y1,z1) after 1 second.
So to draw that line just fill in the points as fine as you like for as long as required, such as every 1/1000 of a second for 10 seconds or something, might draw a "line", really a series of points that when seen from a distance appear as a line, over 10 seconds worth of distance, determined by the "speed" you choose.