I'm making a 2D game and got stuck on a mathematical issue. How do I find this missing X in the vector2 point in the picture illustration above?
Any help is appreciated!
I have tried to think in terms of Math.Cos() for the x value but that would require an exact angle which I usually get from two vector2s and I only have one and a half vector2 and getting the X in this vector2 is what I'm after.
CodePudding user response:
Solve equation (cx,cy
in circle center) for circle:
(x - cx)^2 (y - cy)^2 = r^2
In your case y
is known and
(x - cx)^2 = r^2 - (yy - cy)^2
If right part is negative, there is no solution.
If right part is positive, there are two possible solutions
x1 = cx - sqrt(r^2 - (yy - cy)^2)
x2 = cx sqrt(r^2 - (yy - cy)^2)
If right part is zero - one solution x = cx
CodePudding user response:
I actually solved the question with the help of another math forum, the answer is in the picture here. enter image description here