# Find position of point using a direction and origin vector

This question is in relation to a programming issue I need to solve, it is to be used in a camera to find the position of the players cursor relative to a flat plane (at a known y coordinate)

Below is an image of the problem:

Apologies if the image is not clear enough, but essentially the problem definition is:

1. We have a known origin O and a known direction dhat
2. We need to find the components px and pz
3. py = 0
4. The distance between O and p is unkown

If I had a distance I could've used simple vector scaling, but this problem is a little out of my depth as it requires the computation of two variables (px and pz). Any assistance or direction would be appreciated.

• You can still use “simple vector scaling.” Think about what similar triangles there might be in this diagram.
– amd
Nov 12, 2018 at 4:41
• The only simple triangles I could think of defining would be O -> (O.x, 0, O.y) -> p, but since we dont know the x and y coords of p I would think this impossible to define a simple triangle. Unless I'm barking up the wrong tree? Nov 12, 2018 at 4:49
• “Similar,” not “simple.”
– amd
Nov 12, 2018 at 4:50
• Ah! I think I have it. We can define a triangle with height Oy, with angles: angle of the direction vector (a), 90 degrees (b) and, 180 - a - b = (c). From there we can use the sine rule to get the length of the hypotenuse (h), h = (Oy / sin (c)) * sin (b). Is this method sound? Nov 12, 2018 at 5:09

You have a line: $$o + tv$$, where $$o$$ is your camera and $$v$$ is the direction. Thus we have (0,10,0) + t(.7071,-.7071,0). So we can solve for t in the y-coordinate and use that t value for x and z.Note that the z coordinate will always be 0. This is true, coordinate wise as well. So we can solve for t.

y-coordinate:$$10 - t(.7071) = 0$$ $$t=\frac{10}{.7071}$$ Thus $$x = \frac{10}{.7071}$$

• So is this solution only valid if dZ is always 0? As this was just an example unit vector, dZ is not always going to be 0 unfortunately Nov 12, 2018 at 4:17
• Ah wait, I think I see what you mean. Just in this example it is 0. So if dZ (for example) was 0.5, to find the coordinate pZ we would use pz = 10 / 0.5? Nov 12, 2018 at 4:20
• What's dZ again? Nov 12, 2018 at 18:21

Thanks to assistance from amd I managed to find the solution using basic trangle geometry and the sine rule.

We use the below to find the distance between the origin and the final hit point at poisition y = 0.

Then to find the actual point, we simply do the operation O + (d * h), this will give the resultant vector p