Editorial for ECOO '12 R1 P3 - Triangles


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

First, figure out the angle (\theta) and length (L) of the line from the origin to the given point P (use \tan^{-1} for the angle and the Pythagorean Theorem for the length). Points Q and R are also at a distance of L from the origin, but at angles \theta-60^\circ and \theta+120^\circ respectively. You can use \sin and \cos to get these points. (Another way to do this is to notice that the points are reflections of one another in the line y=x, so once you have one you just flip the sign of the coordinates to get the other.)

The third point is trickier. Figure out where point S is (it's at angle \theta+60^\circ and at a distance of L from the origin). Now the final point you want is on the perpendicular bisector of PS, at a distance of 2h from the origin, where h is the height of the small triangles (use the Pythagorean Theorem to get h). You can get the angle of the perpendicular bisector using the negative reciprocal of the slope of PS and \tan^{-1}. And you know this line goes through the origin. Now use \sin and \cos to get the coordinates of T.

Pitfalls

You have to remember that your computer probably thinks in radians, not degrees. So you have to do the proper conversions. Every time you compute a new angle for a point, you may have to correct it to make sure you are within 0 to 360^\circ, and you may also have to correct it to make sure it is in the same quadrant as the x and y you used to compute it. (e.g. if x=-10 and y=-10, \tan^{-1}(y/x) = 45^\circ, but this puts you in Quadrant I. You need to add 180^\circ in this case to get the real angle.) You also have to watch out for vertical and horizontal lines and you may need to treat them as special cases.


Comments

There are no comments at the moment.