Accelerometer calibration
Time limit1sMemory limit256 MB
Recover each accelerometer's sinusoidal error model from four calibration readings, then invert the two readings to compute the device rotation angle.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Implementation
- Solved
- No attempts yet
Problem
Modern smart devices can work as GPS navigators and step counters. They can tell whether the user is walking, running, taking a taxi, or riding a bus, and they can automatically reorient the image on the screen. To do these and many other tasks, they rely on devices called accelerometers. A simple single-axis accelerometer has a direction called its sensitivity axis. Readings from a stationary accelerometer let us compute how far this axis deviates from the downward vertical, that is, from the gravity vector. If several single-axis accelerometers are mounted on a device, the positions of their axes can determine the device's orientation in space.
A perfect accelerometer measures the cosine of the angle between its sensitivity axis and the direction of gravity. If the sensitivity axis points downward, along the gravity vector , the accelerometer shows ; if it points upward, it shows . If the axis is tilted at an angle to the vertical, the reading of the perfect accelerometer equals the projection of the gravity vector onto the axis.

Manufacturing miniature accelerometers is not completely free of defects. Sensor defects cause the following errors in readings:
- the sensitivity axis of the accelerometer deviates from the correct direction (bad mounting);
- a proportional change in readings, meaning that all readings increase or decrease by a common factor;
- a systematic shift of all readings by some constant.
If several accelerometers are installed in a device, these errors can differ for each accelerometer. However, if we examine a series of readings from one accelerometer in different positions, the errors affect all its readings in the same way.
To determine the exact nature of the errors in accelerometer readings so they can be corrected digitally, accelerometers are calibrated. One calibration method is to collect readings in several strictly defined device positions and compute the parameters of the defects described above for each accelerometer in the device. These parameters can then be used to compute the device's orientation in an arbitrary position.
In this problem, we consider a device with two rigidly mounted accelerometers. When the device is in the standard orientation in space, one accelerometer must point to the right along the axis, and the other must point up along the axis, opposite to gravity. The user can rotate the device. Assume that rotation is possible only in the plane. In this case, the device's orientation is completely determined by the angle of counterclockwise rotation around the axis from the standard orientation. Counterclockwise means from the axis to the axis.


To calibrate such an accelerometer, readings are taken when the device is rotated by a number of degrees divisible by 90. This determines all defect parameters.
Using the given calibration datasets, determine the defect parameters and find a way to compute the device's actual orientation from accelerometer readings.
Input
The first four lines of the input contain the accelerometer readings when the device is rotated by , , , and , respectively.
The next line contains an integer , the number of readings for which the device position must be found (). Each of the remaining lines contains accelerometer readings for a device orientation that must be computed.
Each reading contains two space-separated real numbers: the reading of the first accelerometer, oriented along the axis, and the reading of the second accelerometer, oriented along the axis. Both numbers are given with 15 digits after the decimal point.
The readings in the input are guaranteed to be obtained using the measurement and error model described in the statement. The errors in readings cannot be too large. The deviation of the sensitivity axis from the correct direction is never greater than , the proportional change never changes the readings by more than a factor of two, and the absolute value of the shift is never greater than .
Output
Print numbers, one per line. Each number is the device's rotation angle in degrees for the corresponding accelerometer readings. The rotation angle must be between and , inclusive. The relative or absolute error of each answer must not exceed .
Hint
In the first example, the accelerometers have no defects. In the second example, all three error components affect both accelerometers, to different degrees.