Running Lights Visibility Calculator |
Ships underway on the high seas at night are required to display navigation lights to identify their location and direction of movement to other ships. Most ships we required to display a set of four running lights: one at the stern (rear), one in the middle on the mast, and two at the bow (front).
In naval practice, the course of a ship is the direction the ship is
traveling as measured clockwise from true north. For
example, a ship that is traveling due east is on a 90 course; one traveling
on a 315
course is traveling due west-northwest. The relative bearing
from ship A to ship B is the measure of the angle that the course of ship A makes
with the vector drawn from A to B, where the initial side of that angle
is incident with the course vector and the
terminal side is incident with the vector from A to B.
Thee measurement is taken clockwise.
If we assume that the bow of a ship is pointing to 0.0 or 360.0
, then the
running lights have ranges as shown in the
figure. Here, the stern (rear) of the ship is at 180.0
. The masthead light
shines all directions (0.0
- 360.0
). The
stern light shines strictly between 110.0
and 250.0
(the angle at which
the stern light is beamed relative to the ship
satisfies the inequalities
). The red running light
shines strictly between 245.0
and 2.5
; the
green running light shines strictly between 357.5
and 115.0
. (Note the
overlap in the visible sectors between the
red and green running lights and stern light.) In adition, the nominal
maximum light visibility range for all lights is
10 nautical miles (nm).
Write a computer program that will repeatedly read in sets of data describing the location, course and speed of your own ship and other ships in the vicinity. Based on this information, the program will first calculate the relative bearings from other ships to your ship and display the expected configurations of visible lights from left to right as viewed from your own ship. Ships at least 10 nm away will not be visible.
The program then recalculates the relative
bearings after a 3 minute time delay to determine which ships are on a
collision course with your own. If another
ship is initially visible and if at the end of the 3 minute delay the
relative bearing from that ship to your own remains
almost the same (within 2 ) while the distance between the ships decreases,
then the program must issue a collision
warning. Assume that there will be no collisions of any type
(ship-to-ship or ship-to-land) in the 3 minute time period.
The input file consists of several data scenarios. Each scenario is as follows.
Scenario ID (string)Number of other ships (integer)
Information on your own ship on two lines:
name of your ship (string)
x-coordinate y-coordinate course speed (reals)
Other ship information on two lines per ship:
name of other ship (string)
x-coordinate y-coordinate course speed (reals)
All coordinates are on a cartesian grid with unit measurement of 1 nautical
mile. Courses are measured from true
north, and each course satisfies . Speeds are in
knots (1 knot = 1 nm/hr). The end of input is
indicated by end-of-file.
Output consists of a single table per data set. A table shows the ID for each other ship along with its initially calculated relative bearing to your own ship, distance from your own ship, and its light configurations (from left to right) visible from your ship. Specific table spacing is not critical but output should be easily readable. Collision warnings, if any, should appear at the bottom of the table. Each warning should include the name of the other ship and its distance from your own ship at the end of the 3 minute interval. (Do not display the relative bearings, distances, or running lights configurations for the end of that warning interval.)
All real output should be written with two digits to the right of the decimal. Separate output for different scenarios with a line of asterisks.
Sample Test Data Set 4 Ownship 0.0 0.0 90.0 10.0 Windswept 10.0 10.0 135.0 8.0 Footloose -5.0 6.0 275.0 6.0 Crasher 0.0 9.0 135 14.14 Aquavit -2.0 -2.0 294.0 15.0
Scenario: Sample Test Data Set Boat ID Bearing Distance Lights (left to right) --------------------------------------------------------------- Windswept 90.00 14.14 Lights not visible Footloose 225.19 7.81 Masthead Stern Crasher 45.00 9.00 Masthead Green Aquavit 111.00 2.83 Stern Masthead Green ** Collision warning -->Crasher: Distance = 8.50 ***************************************************************