3
$\begingroup$

I'm not a student, I'm just a programmer trying to solve a problem ... I just need the practical way to calculate the smallest angle between two lines that intersect. The value, of course, must always be less than or equal to 90 º. For ease, imagine the hands of a clock as line segments, starting from a common vertex at its center. At 12 o'clock we have 0° and 360°, at 3 o'clock we have 90, at 6 o'clock we have 180, at 9 am have 270, ie, the angles range from 0 to 360° clockwise ALWAYS. This is my reference.

Each hour is 30 degrees (360/12), so suppose one of hands is in position 1h and the other one is in position 11h. Using my reference, which always starts at zero from 0 hours (or 12 hours, whichever you prefer) we have:

1h Position is equivalent to 30° 11h position is equivalent to 330°

I know, looking at the clock, the result I hope to find is 60°, however I need a mathematical relationship where I tell two angles starting from the same source and I get as result a value that is the smallest angle by two intersecting lines.

OBS.: I really do not need explanations about lines in Cartesian planes or angular coefficient. I really do not have these informations. What I have are only two angles relative to each other to form imaginary lines and I need only calculate the smallest angle between these lines. Thanks for understanding!

$\endgroup$

2 Answers 2

3
$\begingroup$

Given two angles $\alpha$ and $\beta$ in degrees, the required one would be: $$\gamma=min(|\alpha - \beta|, 360-|\alpha-\beta|)$$

Edit: Seems there is a nicer formula $$\gamma=180 - ||\alpha-\beta|-180|$$

$\endgroup$
5
  • $\begingroup$ Hi gev! Thank you for you answer. I suppose it's close :). In fact this expression works for some tests (angles) but, using my example with the angles being 30 and 330 degrees, we have x = (330 - 30 - 180) mod 180 x = (120) mod 180 x = 120 But the correct answer would be 60 degrees. I'm using the windows calc in scientific mode and doing 120 mod 180. I know the mod operator is the remainder of a integer division. Do you have another way to do this? $\endgroup$ Mar 26, 2013 at 14:37
  • $\begingroup$ Hmm, I think I made an error there. Let me review it. $\endgroup$
    – gev
    Mar 26, 2013 at 14:40
  • $\begingroup$ Hi gev! Thank you, but, my math skills are very bad today... The vertical pipe means "absolute value"? If so, I will test it soon! $\endgroup$ Mar 26, 2013 at 20:34
  • $\begingroup$ Right, that's absolute value. $\endgroup$
    – gev
    Mar 26, 2013 at 20:45
  • $\begingroup$ Hi Gev, everything is tested! Your answer was choosed as the "more beautiful" between the two answers. The another one was from Kamil and his answer was correct too. Thank you both :) $\endgroup$ Mar 27, 2013 at 2:02
2
$\begingroup$

I would say it's: $$ \gamma=min((360-\alpha+\beta) mod 180, (360-\beta+\alpha) mod 180) $$ especially when you're a programmer ;) (so am I ;))

$\endgroup$
2
  • $\begingroup$ Hi Kamil, thanks for the answer! I will test it soon... $\endgroup$ Mar 26, 2013 at 20:35
  • $\begingroup$ Hi Kamil! Your answer is correct, thank you! In fact your sollution is more near to me as programmer, however, the answer from Gev is a little bit more compact and you know how this is important, right?! Thank you so much for this ALSO CORRECT ANSWER! $\endgroup$ Mar 27, 2013 at 2:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .