Sailing boat - algorithm beating or not

Hello everyone

I have problems designing an algorithm for my rc sailing boat which decides if the course given is possible to sail or if it is necessary to go beating.

I have given the direction of the wind, which can be calculated by the direction relative to the boat and a compass, and a direction the boat should go transferred to the arduino by rc.

My trouble is now to define the sector of the circle (0-359degrees), in which the boat has to beat and cannot sail directly.
My idea was to define : direction is ok if smaller than wind direction - 35 degrees, or bigger than wind direction + 35 degrees.
This unfortunately only works if the north (0 degrees) is between these two boundaries. I don't know how to define it for the case that e.g. the sector is 280 - 350 degrees.

I hope it is understandable what I mean, thank you for all help :wink:
PS: please link me to any topic where this problem is already discussed, but I didn't find any :confused:

You can add your current heading (compass input) to the relative wind direction (direction indicator input) to get absolute wind direction. Then you can compare that absolute wind direction to the desired heading to see the desired heading is too close to the wind.

For example:
Current heading: 45°
Relative wind: Coming from 210°
Absolute wind: 255° (210+45+360 modulo 360)
Available headings: below 220° (255-35+360 modulo 360) and above 290° (255+35+360 modulo 360)

If the math crosses the 0° boundary:
Current heading: 55°
Relative wind: Coming from 310°
Absolute wind: 5° (310°+55°+360 modulo 360)
Available headings: below 330° (5-35+360 modulo 360) and above 40° (5+35+360 modulo 360)

Note: the integer modulo operator is %

AbsoluteWind = (CurrentHeading + RelatveWind + 360) % 360;

Thank you very much!
I didn't realize it was that easy, I thought way too far :stuck_out_tongue: