Under construction

Still being built. Things may change

Archimedes

Time limit1sMemory limit1024 MB

Summary
Given the spiral constant b and a target point, find the point on the spiral r = b * phi where the avatar must leave along its tangent to hit the target.
Level

Medium7 of 10

Topics
Geometry, Math, Binary search
Solved
No attempts yet

Problem

Archimedes's Spiral, b=12b = \frac{1}{2}

Archimedes is a new 2D video game with very simple rules. The player presses start, and the avatar begins moving along an Archimedean spiral from the origin. When the player presses a button, the avatar detaches from the spiral and keeps moving in the direction it is heading at that moment. The goal is to hit a target. After the avatar detaches, its path must not intersect any part of the spiral.

To study this game, write a program that takes the angular velocity of the spiral and computes the point where the player must press the button to release the avatar and hit the target.

An Archimedean spiral is traced by a point moving at constant speed along a line that rotates at constant angular velocity around the origin. In polar coordinates (r,ϕ)(r, \phi), the spiral is r=b ϕr = b \ \phi. Here rr is the distance from the origin, and ϕ\phi is the angle between the point, the origin, and the unit vector (1,0)(1, 0). The constant bb sets the distance between successive rings of the spiral.

Input

The input is a single line with three real numbers bb, txt_x, and tyt_y. Here bb is the parameter of the spiral r=b ϕr = b \ \phi, and T=(tx,ty)T = (t_x, t_y) is the target.

The constraints are 0.01≤b≤100.01 \le b \le 10 and −10 000≤tx,ty≤10 000-10\,000 \le t_x, t_y \le 10\,000. It is guaranteed that tx2+ty2>2πb\sqrt{t_x^2+t_y^2} > 2 \pi b, so the avatar stays on the spiral for at least one full 360 degree turn. The distance from TT to the closest point on the spiral is greater than 10−310^{-3}. The value bb has up to 12 significant digits, and txt_x and tyt_y have up to 3 digits after the decimal point.

Output

Print the xx and yy coordinates of the point on the spiral where the avatar leaves the spiral. After leaving, the avatar keeps moving in the same direction and hits the target without intersecting the spiral.

An answer is correct if the absolute or relative error of both xx and yy is at most 10−510^{-5}.

Examples5

  1. Example 1

    Input
    0.5 -5.301 3.098
    
    Expected output
    -1.26167861 3.88425357
    
  2. Example 2

    Input
    0.5 8 8
    
    Expected output
    9.21068947 2.56226688
    
  3. Example 3

    Input
    1 8 8
    
    Expected output
    6.22375968 -0.31921472
    
  4. Example 4

    Input
    0.5 -8 8
    
    Expected output
    -4.36385220 9.46891588
    
  5. Example 5

    Input
    0.5 0 -8
    
    Expected output
    -3.60855706 -3.61140618