Search code examples
math3dline

Find a new 3D position from a known point of origin, based on distance and angle


My maths is very rusty and I've never been great at imagining things past 2 dimensional space.

My question is this. Given a point of origin (p1), how can I calculate a new point (p2) which is a known distance (100 units) based on two angles (Yaw and Pitch).

What I know is the 3D dimensions for a virtual room, the point of origin within that room and the Yaw and Pitch (I've called this horizontal angle and vertical angle). To put it in to English, I would like to fire a line of 100 units within this room from that point of origin based on it's Yaw and Pitch values and get the point at the end of that line.

I would like this point in space because I would like to define my line using p1 and p2. I want to eventually go on to use this line in a line/plane intersection test. The planes are also known within the virtual room. I only mention this because with my lack of mathematical knowledge, someone may suggest I look at some other method.


Solution

  • If you just want to define a line, you don't need the second point. The line's direction vector can be calculated directly as:

          / cos pitch * sin yaw \
    dir = | sin pitch           |
          \ cos pitch * cos yaw /
    

    This assumes that the y-axis points upwards. A zero yaw points in positive z-axis. Increasing yaw will turn the direction towards the positive x-axis. These definitions are all interchangeable.

    The line is then:

    x = startPoint + t * dir  |  t \in R
    

    If you really want the second point, just use 100 as t and calculate x.