2
votes

implementing this on MATLAB for my project.

I have a circle divided up to 3 arcs. So the angle range of each arc is [0,120), [120,240), [240,360) degrees.

Right now I have a code that finds whether the angle lies in arc A, B, C given any theta.

theta = mod(theta,360);
if theta >= 0 && theta < 120
    Arc = A;
elseif theta >= 120 && theta < 240
   Arc = B;
elseif theta >= 240 && theta < 360
   Arc = C;

This works just fine. Here is the situation that I am struggling to get to:

The circle can rotate by the angle phi.

So for example, if the circle rotated clockwise 30 degrees, the range of my angle will be [30,150), [150,270), [270,390)

How should I write my if statement to deal with this case? My theta input can range from 0 to infinity, so I tried to do modulus division to get to [30,150), [150,270), [270,30)

but now I am stuck how to make it generalized so it can work for any input of theta and phi input that ranges from [0,360)

Thanks in advance with your advise.

1

1 Answers

2
votes

If you know the angle the circle is rotated by (as you say, phi = 30°), then just use theta-phi instead of theta. The rest of the code stays the same:

theta = mod(theta-phi,360);
if theta >= 0 && theta < 120
   Arc = A;
elseif theta >= 120 && theta < 240
   Arc = B;
elseif theta >= 240 && theta < 360
   Arc = C;

Alternatively, you can add the phi to all angles:

theta = mod(theta,360);
ranges = mod([0 120; 120 240; 240 360])
if theta >= 0+phi && theta < 120+phi
   Arc = A;
elseif theta >= 120+phi && theta < 240+phi
   Arc = B;
elseif theta >= 240+phi && theta < 360+phi
   Arc = C;

Use whatever you find most intuitive; the performance impact of the six additions versus the single addition is completely negligible.

EDIT: forget the second method, it's far too messy.