在3D空间中,如何计算一个点在一定的高度,即线性与其他2个已知点? [英] In 3D space, how do I calculate a point at a certain height, that is linear with 2 other known points?

查看:212
本文介绍了在3D空间中,如何计算一个点在一定的高度,即线性与其他2个已知点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我工作的一个3D游戏,在这里我需要我的鼠标输入转移到了一定的高度,在3D的世界,所以我可以在一个表面上移动一个单元。

I am working on a 3d game, where I need to transfer my mouse-input to a certain height in the 3d world, so I can move a unit across a surface.

这是从一个倾斜的摄像头的视角进行(45辈分倾斜)。在playcanvas API提供我与我的相机功能,可以使用一组深度翻译我的鼠标输入的2D屏幕上,进入3D世界。

This is done from the perspective of a tilted camera (45 degress tilted). the playcanvas API supplies me with a function on my camera, which can translate my mouse input on the 2d screen, into the 3d world using a set depth.

当我把我的深度为0,我得到我的相机的精确坐标(在此情况下(0,80,80),如果我设置深度为100,我得到〜(0.09,11.52, 7.06)...

when I set my depth to 0, I get the exact coordinates of my camera (which in this case is (0,80,80), and if I set the depth to 100, I get ~(0.09, 11.52, 7.06)...

我需要一种方法来找出或者其中两个点之间的线路击中的高度(2 y轴),或者我能找到一种方法来计算我需要提供摄像头,以深度的坐标回到我所需要的坐标

I need a way to figure out either the coordinates where the line between the two points hits the height (y-axis of 2), OR I could find a way to calculate the depth I need to supply the camera in order to get back the coordinates I need

这使我:

我在三维空间坐标2:假设P1(0,80,80)和P2(0.09,11.52,7.06)

I have 2 coordinates in 3d space: let's say p1(0, 80, 80) and p2(0.09, 11.52, 7.06).

我想弄清楚如何计算一个第三点,其中y = 2,这一点应该与其他2点对齐。

I want to figure out how to calculate a 3rd point, where y = 2. This point should be aligned with the 2 other points.

任何建议,我如何能做到这一点?我在寻找用尽可能少的计算,可能的一个解决方案。

Any suggestions to how I can achieve this? I am looking for a solution with as few calculations as possible.

推荐答案

做的是写一个家庭式的描述所有的空间都是共线P1和P2点的一种方法。

One way to do it is to write a family of equations that describes all of the points in space that are collinear with p1 and p2.

x = x1*t + x2*(1-t)
y = y1*t + y2*(1-t)
z = z1*t + z2*(1-t)

...其中X1,Y1,Z1是p1的坐标,同上为p2和 T 是任何实数。

我们可以通过解 T 找到我们特别希望的点的坐标。我们知道,Y = 2,所以我们要重新排列方程。

We can find the coordinates of our particular desired point by solving for t. We know that y = 2, so we'll rearrange that equation.

y = y1*t +y2 - y2*t
y - y2 = y1*t - y2*t
y - y2 = (y1 - y2)*t
(y - y2) / (y1 - y2) = t
t = (y - y2) / (y1 - y2)

现在你知道T,你可以将它插入剩下的两个方程得到你的X和Z值。

Now that you know t, you can plug it into the two remaining equations to get your x and z values.

这篇关于在3D空间中,如何计算一个点在一定的高度,即线性与其他2个已知点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆