I need to limit an angle so it fits into a segment. I have drawn and links to a diagram below to better describe what I am after.
I am trying to calculate this for a computer program, where I have an angle (slope), and a point (the mouse pointer). The distance does not matter to me, just the angles. If the point is within b1 (green area) then that’s fine. But if the point is within b2 or b3 (red or orange) areas, then the angle should snap back to the limit of the green area (along the line s).

(source: adamharte.com)
The main problem I am having in figuring this out, is snapping the angle to the correct side e.g. If the point is in the red area, then the angle should snap to the angle s on the red side and vice versa.
I am also having trouble because s could be any angle, so I am being tripped up because I can’t just do something like this:
if a(radians) is greater than
s(radians) then set a to the value of s
or I will get errors when the angle goes between zero and 2Pi.
So How would I work this out? Do I have to rotate everything back to a zero point or something then put it back when I have made my calculations?
Thanks for reading my questing.
First code in an ATAN2() function, to calculate the absolute angle for the point relative to horizontal plane. Then subtract the angle of the slope. if the result is <0 then snap to 0 and if the result is >180 snap to 180. The add the angle of the slope back to get your final angle
try it.