Under construction

Still being built. Things may change

Two-Wheel Buggy

Time limit8sMemory limit512 MB

Summary
Simulate a two-wheeled buggy through N timed wheel-speed instructions and print the final axle position to five decimals.
Level

Medium5 of 10

Topics
Geometry, Simulation, Math
Solved
No attempts yet

Problem

The car maker International Car Production Company (ICPC) is developing a new vehicle called Two-Wheel Buggy. As the name says, the vehicle has only two wheels. The buggy is made of a left wheel, a right wheel, and an axle, which is a bar joining the two wheels.


Figure 1: The basic structure of the buggy

Before building a prototype, the company decided to run a computer simulation. The rules of the simulation are below.

The buggy moves on the x-y plane. Let DD be the distance from the center of the axle to each wheel. When the simulation starts, the center of the axle is at (0,0)(0, 0), the left wheel is at (−D,0)(-D, 0), the right wheel is at (D,0)(D, 0), and the buggy faces the positive yy direction. Both wheels have radius 1.


Figure 2: The initial position of the buggy

A sequence of instructions controls the movement of the buggy. One instruction is three numbers, LspeedLspeed, RspeedRspeed, and timetime. LspeedLspeed and RspeedRspeed are the rotation speeds of the left wheel and the right wheel in degrees per second, and timetime is how many seconds the two wheels keep those speeds. A positive speed turns a wheel in the direction that drives the buggy forward, and a negative speed turns it the other way. For example, with LspeedLspeed set to −360-360, the left wheel makes one full turn per second in the direction that drives the buggy backward. You can set LspeedLspeed and RspeedRspeed to different values, and the buggy then turns left or right. You can also set one of them positive and the other negative. The buggy then spins around.


Figure 3: Examples of movement

Write a program that computes the final position of the buggy for a given instruction sequence. Assume the wheels have no width and never slip.

Input

The input holds several datasets. Each dataset has the form below.

N D
Lspeed_1 Rspeed_1 time_1
...
Lspeed_N Rspeed_N time_N

The first line of a dataset holds two positive integers NN and DD (1≤N≤1001 \le N \le 100, 1≤D≤101 \le D \le 10). NN is the number of instructions, and DD is the distance from the center of the axle to each wheel. Each of the next NN lines holds three integers LspeediLspeed_i, RspeediRspeed_i, and timeitime_i (−360≤Lspeedi,Rspeedi≤360-360 \le Lspeed_i, Rspeed_i \le 360, 1≤timei1 \le time_i) describing the ii-th instruction. The sum of timeitime_i within one dataset is at most 500.

A line holding two zeros marks the end of the input. That line is not a dataset, so do not process it.

Output

For each dataset, print the final position of the center of the axle on two lines. Print the x-coordinate on the first line and the y-coordinate on the second line. Round both coordinates to exactly five digits after the decimal point. When a rounded coordinate is zero, print 0.00000 and not -0.00000. Print no other characters.

Examples3

  1. Example 1

    Input
    1 1
    180 90 2
    1 1
    180 180 20
    2 10
    360 -360 5
    -90 360 8
    3 2
    100 60 9
    -72 -72 10
    -45 -225 5
    0 0
    
    Expected output
    3.00000
    3.00000
    0.00000
    62.83185
    12.00000
    0.00000
    -2.44505
    13.12132
    
  2. Example 2

    Input
    1 1
    360 360 1
    1 1
    -180 -180 1
    1 1
    0 0 1
    0 0
    
    Expected output
    0.00000
    6.28319
    0.00000
    -3.14159
    0.00000
    0.00000
    
  3. Example 3

    Input
    1 10
    360 360 500
    0 0
    
    Expected output
    0.00000
    3141.59265