General Question

gorillapaws's avatar

Geometry Gurus. Can you help me solve for an angle?

Asked by gorillapaws (30808points) February 22nd, 2015

I’m working on an app and I need to solve for an angle. I have 2 points and I need to solve for the angle that would be produced from an arc that began drawing at “3 o’clock” counterclockwise to a point on it’s circumference. That’s not a great description, so I’ve uploaded a diagram.

The centerPoint can be arbitrary but the coordinates are known. I’ve been using the following expression:
angle = acos( (radialPoint.x – centerPoint.x) / radiusLength )
This seems to work when the angle is < 180 but it fails when the angle is > 180.

Is there a function to easily calculate the angle with the coordinates of both points known? I’m sure I could come up with something crazy involving slopes and checking for various cases, but that seems pretty ugly if there is an easy answer.

Observing members: 0 Composing members: 0

2 Answers

jerv's avatar

The simplest solution would indeed be to have an IF…ELSE… statement there and have two separate cases depending on whether (RadialPointY – CenterPointY) is positive (@Angle < 180) or negative (@Angle > 180).

The issue here is that (RadialPointX – CenterPointX) can be the same for two separate points along a circle of a given radius at different angles. If we assume that your picture there places KnownCenterPoint at 10,10 then plot the line X=5 and see how many places it intersects that pink-shaded area, it appears to be that that line would intersect that arc at angles of 135 degrees and 225 degrees. Which of those values it actually is cannot be determined without some sort of test of (RadialPointY – CenterPointY).

gorillapaws's avatar

@jerv Thanks for the response. That’s what I thought was going on, but I wasn’t sure if there was an easier way. I figured I’d check before writing conditionals.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther