TopCoder problem "FixedPoint" used in TCHS SRM 21 (Division I Level Two)



Problem Statement

    

The country of Byteland can be represented as a plane of infinite size. If you place a map of Byteland on the ground anywhere within the country, there will be exactly one "fixed point". This is the point on the plane that is at the exact same location as its representation on the map.

The map of Byteland has been created and placed by performing the following three transforms, one by one in order, on the original plane.

  1. 1. Scale it to a smaller size using a positive double scaling factor scale. Each point (x, y) in the original plane is transformed to (scale*x, scale*y).
  2. 2. Translate it by a given vector translate. Each point (x, y) is transformed to (x+translate[0], y+translate[1]).
  3. 3. Rotate it by a given angle rotate (in radians). Each point (x,y) is transformed to (x*cos(rotate)-y*sin(rotate), y*cos(rotate)+x*sin(rotate)).
In conclusion, the fixed point (x, y) for this configuration must satisfy the following two equations:
  • (scale * cos(rotate) - 1) * x - scale * sin(rotate) * y = -translate[0] * cos(rotate) + translate[1] * sin(rotate)
  • scale * sin(rotate) * x + (scale * cos(rotate) - 1) * y = -translate[0] * sin(rotate) - translate[1] * cos(rotate)

Solve the above equation and return the fixed point as a double[] containing exactly 2 elements, where the first element is the x-coordinate and the second element is the y-coordinate. There will always be exactly one unique solution.

 

Definition

    
Class:FixedPoint
Method:find
Parameters:double, double[], double
Returns:double[]
Method signature:double[] find(double scale, double[] translate, double rotate)
(be sure your method is public)
    
 

Notes

-A return value with an absolute or relative error less than 1.0E-9 is considered correct.
 

Constraints

-scale will be between 0.1 and 0.9, inclusive.
-translate will contain exactly 2 elements.
-Each element of translate will be between -1000 and 1000, inclusive.
-rotate will be between -1000 and 1000, inclusive.
 

Examples

0)
    
0.5
{1, 0}
1.5707963267948966
Returns: {-0.39999999999999997, 0.8 }
After the scaling transform, (-0.4, 0.8) becomes (-0.2, 0.4). After the translation transform, (-0.2, 0.4) becomes (0.8, 0.4). Finally, after the rotation transform, (0.8, 0.4) becomes (-0.4, 0.8), which is the original point.
1)
    
0.5
{2, 0}
0
Returns: {4.0, 0.0 }
(4, 0) -> (2, 0) -> (4, 0) -> (4, 0)

The three "->"s represent scaling, translation, and rotation, respectively.
2)
    
0.1
{0, 0}
2
Returns: {0.0, -0.0 }
(0, 0) never moves whenever the translate vector is (0, 0).
3)
    
0.5
{1, 2}
0.785398163397
Returns: {-2.223469992542095, 2.065452845425795 }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6795

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10073&pm=6795

Writer:

zhuzeyuan

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Math