Points of Sailing – Python Challenge

When sailing, the direction in which a boat can travel depends on the direction of the wind. Sailors describe the angle between the boat and the wind using different points of sailing, such as close-hauled, beam reach, broad reach and run.

In this Python challenge, you are going to write a program that uses the direction of the boat and the direction of the wind to work out the boat’s current point of sailing.

Boat and Wind Directions

Directions will be represented using angles between 0° and 360°:

  • 0° = North
  • 90° = East
  • 180° = South
  • 270° = West

Your program should start by asking the user to enter two values:

  1. The direction of the boat
  2. The direction the wind is coming from

For example:
Boat direction: 120°
Wind direction: 40°

We will use these two values to calculate the relative angle of the wind (relative to the direction of the boat). However, you cannot simply subtract these two values. Because directions wrap around at 360°, your program needs to calculate the relative wind angle correctly using the following algorithm:

For example, a boat travelling at 20° with the wind coming from 340° has a relative wind angle of only 40°.
The sign of the angle tells you which side of the boat the wind is coming from, while its magnitude tells you the boat’s point of sailing.

Points of Sailing

Once you have calculated the relative wind angle, use selection (if, elif and else) to work out the correct point of sailing.

Relative wind angle Point of sailing
−40° to +40° No-sail zone
40° to 55° Close-hauled
55° to 75° Close reach
75° to 105° Beam reach
105° to 145° Broad reach
145° to 170° Training run
170° to 180° Run

The same ranges apply on either side of the boat (for negative relative angles) This means, for example, that both +90° and −90°, represent a beam reach.

Python Challenge

Write a Python program that:

    Asks the user for the boat direction between 0° and 360°.
    Asks for the wind direction between 0° and 360°.
    Calculates the relative angle of the wind.
    Displays the relative wind angle.
    Uses an if / elif / else selection to identify the correct point of sailing.
    Displays the result to the user.

For example, your program might produce the following output:

Enter the boat direction (0-360): 120
Enter the wind direction (0-360): 40

Relative wind angle: -80 degrees
Point of sailing: Beam reach

Python Code

Complete the Python code below:

Online Points of Sailing Page

You can use our online interactive Points of Sailing page to understand more about the points of sailing and the position of the main sail and the jib on a sailing boat. You can use this page to help you test your program for different wind directions and boat directions.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!