1
$\begingroup$

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:

enter image description here

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.

$\endgroup$
4
  • 1
    $\begingroup$ You can still use “simple vector scaling.” Think about what similar triangles there might be in this diagram. $\endgroup$
    – amd
    Nov 12, 2018 at 4:41
  • $\begingroup$ 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? $\endgroup$
    – Polymer
    Nov 12, 2018 at 4:49
  • 1
    $\begingroup$ “Similar,” not “simple.” $\endgroup$
    – amd
    Nov 12, 2018 at 4:50
  • $\begingroup$ 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? $\endgroup$
    – Polymer
    Nov 12, 2018 at 5:09

2 Answers 2

1
$\begingroup$

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}$$

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – Polymer
    Nov 12, 2018 at 4:17
  • $\begingroup$ 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? $\endgroup$
    – Polymer
    Nov 12, 2018 at 4:20
  • $\begingroup$ What's dZ again? $\endgroup$ Nov 12, 2018 at 18:21
0
$\begingroup$

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.

enter image description here

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

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .