I'm working on a chapter in my book dealing with touch input, and my memory of high school trig (from circa 1988) is failing me. My search here has not yielded anything that I'm capable of applying to this particular problem.
- I have a ship on the screen. If the user touches the screen, I need to turn the ship to align with that point (but over several steps, so I'd do it in increments). To do this, I need to calculate the angle shown in the diagram below.
- The ship's current X and Y location.
- The touch point's X and Y location
Can potentially calculate in case it helps
Arbitrary points along the line starting at the current location and going out to the current heading, given a distance.
Length of hypotenuse (I know the start and end points)
What I need to calculate
- The Angle between the imaginary line which represents the current heading, and the touch point, with the vertex at the current location. This image shows what I'm looking for:
I've been searching all day for anything which will (ahem) trigger a memory as to how to solve this, but I've been hitting nothing useful. Trig was never a strong skill for me in any case.
Sin/Cos/Tan functions need more data than I currently have. I thought about doing something with line intersection to get the length of the opposite side so I could use the Sin function, but I couldn't figure out how to calculate the line perpendicular to the heading and passing through the known touch point.
I'll take anything which works, but I'm doing this calculation frequently, so efficiency (for things which can be represented in code) is a plus.
Thanks for your time here.