Vector/math problem
Hi. I have a vector/math problem. I need get the position (vector3) of P2 (look in the sketch). I have a camera where the mouse is raycasted in a plane (normal to Y, X and Z are the coordinates in the sketch). When the point obtained (X) is so far away from the scene origin (0,0,0), i want to limit it by R (max distance). Im tried normalizing X (the point where mouse cross the plane) and then multiply it by R (P1) but it is a different point. How can i get P2 (the vector origin-P2) ?
I forgot add in the right: P2 magnitude = R
Answer by HummeL_YT · Sep 06, 2020 at 11:22 PM
Oh, my English so bad, but I hope you can understand me )
So as you know R, Vcam.magnitude and if angle between (Vector3.zero to Vcam) and (Vcam to X) = a, you can do this. R ratio to sin (a) like as Vcam.magnitude ratio to angle between (Vector.zero to P2) and (P2 to Vcam) = sin (b). Ok, now we can find b angle by Mathf.Asin(sin (b)). You can find the third angle — 180 - (a + b) = c.
R ratio to sin (a) like as (Vcam to P2).magnitude to sin (c). From this you can find (Vcam to P2).magnitude by R * sin (c) / sin (b).
Now you can just use Camera.transform.forward * (Vcam to P2).magnitude to get P2.transform.position.
Goodluck!
P.S. If you didn`t understand my explanation - I can write it on paper, I have a 2:30 AM, so...
Your answer
Follow this Question
Related Questions
Finding a tangent vector from a given point and circle 1 Answer
instantiate collision on mouseclick 0 Answers
TransformPoint/Direction/Vector Equation? 0 Answers
Calculating Relative angles 1 Answer