selfcompiler's blog

By selfcompiler, history, 7 years ago, In English

We have set of intervals [theta,-theta] . I want to find out the optimal value of theta [-180,180] which lies in the maximum no of intervals . Value of theta can be float . Can you please help me find the way to find out the optimal theta.

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by selfcompiler (previous revision, new revision, compare).

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Got the Answer

Sort the interval start and end values into a single list with a corresponding value for 'S' or 'E' for each one.

Scan the list, when you hit an S increment a counter, when you hit an E decrement a counter. If the counter is higher than the highest value seen so far remember the S and E values for that segment.

For the wrap-around case, simply split each interval that wraps (i.e. angle2 < angle1) into two pieces, one either side of zero. Add [angle1,360] and [0,angle2] as new intervals into the starting set.