HDU - 1700 :Points on Cycle

N - Points on Cycle 

HDU - 1700 

There is a cycle with its center on the origin. 
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other 
you may assume that the radius of the cycle will not exceed 1000.
InputThere are T test cases, in each case there are 2 decimal number representing the coordinate of the given point. OutputFor each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision 
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X. 

NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
Sample Input
2
1.500 2.000
563.585 1.251
Sample Output
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453

思路:很容易想到是求圆内切正三角形的另2个顶点。设已知点(x,y).所求的点为(x1,y1) (x2,y2) 可以得到方程x*x+y*y=r*r;(x-x1)*(x-x1)+(y-y1)*(y-y1)=3*r*r*r;

求出方程组的2个解即可。注意x=0的情况。


#include
#include
#include
#include
#include
using namespace std;
int main()
{
	int T;cin>>T;
	double x,y;
	while(T--)
	{
		cin>>x>>y;
		double r=sqrt(x*x+y*y);
		if(x==0)
		{
			if(y>0)
			{
				printf("%0.3f %0.3f %0.3f %0.3f\n",-r*sqrt(3)/2,-r/2,r*sqrt(3)/2,-r/2);
			}
			else
			{
				printf("%0.3f %0.3f %0.3f %0.3f\n",-r*sqrt(3)/2,r/2,r*sqrt(3)/2,r/2);
			}
			continue;
		}
		double a=(y*y)/(x*x)+1;
		double b=y*r*r/(x*x);
		double c=r*r*r*r/(4*x*x)-r*r;
		double d=b*b-4*a*c;
		
		double y1=(-b-sqrt(d))/(2*a);
		double x1=-(r*r+2*y*y1)/(2*x);
		
		double y2=(-b+sqrt(d))/(2*a);
		double x2=-(r*r+2*y*y2)/(2*x);
		
		if(y1==y2)
		{
			if(x1


你可能感兴趣的:(计算几何)