从 3d 中的起点和角度计算直线

发布于 2024-12-23 22:39:57 字数 145 浏览 0 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(2

长不大的小祸害 2024-12-30 22:39:57

在三角术语中,需要两个角和一个点才能在 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.

翻了热茶 2024-12-30 22:39:57

这条线可以理解为“时间”中的一个点。该方程必须矢量化,或者有一个方向才有意义,因此时间是一种自然的思考方式。因此,3 维直线方程实际上可能是与时间相关的 x、y、z 的三个二维方程,例如:

x = ax*t + cx
y = ay*t + cy
z = az*t + cz

要找到该组方程,假设相机位于原点,(0,0,0) ,而你的点是 (x1,y1,z1) 那么

ax = x1 - 0
ay = y1 - 0
az = z1 - 0

cx = cy = cz = 0

注意

x = x1*t 
y = y1*t 
z = z1*t 

:这还假设线或向量的“速度”是这样的,即 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:

x = ax*t + cx
y = ay*t + cy
z = az*t + cz

To find that set of equations, assuming the camera is at origin, (0,0,0), and your point is (x1,y1,z1) then

ax = x1 - 0
ay = y1 - 0
az = z1 - 0

cx = cy = cz = 0

so

x = x1*t 
y = y1*t 
z = z1*t 

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.

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