#P2013. Determining Boat Position via Lighthouse Signals
Determining Boat Position via Lighthouse Signals
Determining Boat Position via Lighthouse Signals
A boat equipped with an antenna positioning device can determine its location by receiving unique signals emitted by fixed lighthouses. When the boat detects a signal, it rotates its antenna until the signal strength is maximized, which gives the relative direction from the boat to that lighthouse. With information from two lighthouses, the boat's position can be determined.
Both the lighthouses and the boat are located in a rectangular coordinate system where the x-axis points east and the y-axis points north. The boat's heading is given in degrees measured clockwise from north. That is, north = $0^\circ$, east = $90^\circ$, south = $180^\circ$, and west = $270^\circ$. For each lighthouse, the measured angle is the direction from the boat to the lighthouse relative to the boat's heading (measured clockwise). Suppose the boat's heading is \(H\) and the measured relative angle for a given lighthouse is \(r\). Then the absolute bearing from the boat to that lighthouse is \[ \theta = H + r \; (\text{in degrees}). \] Since the unit direction vector corresponding to an absolute angle \(\theta\) (measured from north clockwise) is \[ (\sin\theta, \cos\theta), \] if a lighthouse is at \((x_i,y_i)\) and the boat is at \((u,v)\), then the lighthouse lies along the ray from the boat given by \[ (x_i, y_i) = (u,v) + d\cdot (\sin\theta,\cos\theta)\] for some \(d>0\). Rearranging, we have \[ (u,v) = (x_i,y_i) - d\cdot (\sin\theta,\cos\theta). \] With two lighthouses (indexed 1 and 2), let their data be \((x_1, y_1, r_1)\) and \((x_2, y_2, r_2)\). Define \[ \theta_1 = H + r_1, \quad \theta_2 = H + r_2. \] Then \[ \begin{cases} u = x_1 - d_1\sin\theta_1, \\[6pt] v = y_1 - d_1\cos\theta_1, \end{cases} \] \[ \begin{cases} u = x_2 - d_2\sin\theta_2, \\[6pt] v = y_2 - d_2\cos\theta_2. \end{cases} \] Subtracting, we obtain a system of two linear equations in \(d_1\) and \(d_2\): \[ \begin{aligned} d_1\sin\theta_1 - d_2\sin\theta_2 &= x_1 - x_2, \\ d_1\cos\theta_1 - d_2\cos\theta_2 &= y_1 - y_2. \end{aligned} \] The determinant of this system is \[ \Delta = \sin\theta_1(-\cos\theta_2) - (-\sin\theta_2)\cos\theta_1 = \sin(\theta_2-\theta_1). \] Assuming \(\Delta \neq 0\), one can solve for \(d_1\) and then determine the boat's position via \[ (u,v)=\left(x_1-d_1\sin\theta_1,\;y_1-d_1\cos\theta_1\right). \]
Your task is to write a program that reads a set of inputs and outputs the boat's coordinates.
inputFormat
The input consists of a single line containing 7 space‐separated numbers:
- H: the boat's heading in degrees (measured clockwise from north).
- x1 and y1: the coordinates of the first lighthouse.
- r1: the measured relative angle (in degrees) from the boat's heading to the first lighthouse (measured clockwise).
- x2 and y2: the coordinates of the second lighthouse.
- r2: the measured relative angle (in degrees) from the boat's heading to the second lighthouse.
All angles are in degrees.
outputFormat
Output the boat's coordinates as two numbers (u and v), separated by a space. The coordinates should be accurate to at least three decimal places.
sample
0 10 100 0 110 20 90
10.000 20.000
</p>