幾何学的予備ベクトルの回転のRescue The Princessを計算します。

3211 ワード

タイトルの住所:http://acm.upc.edu.cn/problem.php?id=2217
テーマの説明
    Several days ago,a beast caght a beautiful princess and the princess was put in prinson.To recue the princess,a prince who wanted to marry  the prince s s set out immediately.Yet,the beast set a maze.Only if the prince find out the maze's exit can he save the princess.
    Now,here cores the proble.The maze is a dimensional pline.The beast is smart,and he hidden the princess snugly.He markd two coordinal of an equilateral triangle t he maze.The twomaked coordinaties ara A(x 1,y 1)and B(x 2,y 2).The third coordiname C(x 3,y 3)isthe maze's exit.If the prinininnce can find the exit、hecan the the the the prinininininininininininininininininininnce.Afs.ininininininininininininininininininininininncs.Afs.Afs.inininininininininininininininininininininininininininininininininininininesn’t know where t he C(x 3,y 3)is.The prince need your help.Can you cacacaculate the C(x 3,y 3)and tell him?
入力
    The first line is an integer T(1==T==100)which is the number of test cases.T test cases follow.Each test case contains two coordinans A(x 1,y 1)and B(x 2,y 2)described byurfont flant ( |x 1|、124; y 1𞓜、124; x 2 124;、124; y 2 124; <= 100.0)    Please notice that A(x 1,y 1)and B(x 2,y 2)and C(x 3,y 3)arin an anticlockwise direction from theequilateral triangle.And coordination A(x 1,y 1)and B(x 2,y 2)ar given by anticlockwise.
出力
    For each test case,you Shouuld output the coordinate of C(x 3,y 3)は、the reult shound be rounded to 2 decimal place in a line.
例の入力
4
-100.00 0.00 0.00 0.00
0.00 0.00 0.00 100.00
0.00 0.00 100.00 100.00
1.00 0.00 1.866 0.50
サンプル出力
(-50.00,86.60)
(-86.60,50.00)
(-36.60,136.60)
(1.00,1.00)
二等辺三角形で、二つの点a(x 1、y 1)とb(x 2、y 2)をあげます。第三の点を求めて、反時計回りの順に求めます。
ここは純粋な三角関数で作ったものです。
#include <stdio.h>
#include <math.h>
int n;
double xx1,xx2,yy1,yy2;
int main() {
	double l, atana, pi = 3.14159265358;
	freopen("in.txt", "r", stdin);
	scanf("%d", &n);
	while(n--){
		scanf("%lf %lf %lf %lf", &xx1,&yy1, &xx2, &yy2);
		double tmp = (double)(xx2-xx1) * (xx2-xx1) + (yy2-yy1)*(yy2-yy1);
		l = sqrt(tmp);
		atana = atan2((yy2-yy1) , (xx2-xx1)) + pi/3;
		printf("(%.2lf,%.2lf)
", cos(atana)*l + xx1, sin(atana)*l + yy1); } return 0; }
ここに導き出す公式があります。http://www.cnblogs.com/E-star/archive/2013/06/11/3131563.html
任意の点A(x,y)に対して、Aは原点ではなく、原点を回ると考えられます。θ角の後の点の座標は:(x*cos)です。θ- y * sinθ, y*cosθ + x * sinθ)
それでまたこの解法があります。
ヽoo。ツ。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。   ヽoo。ツ。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。   要点 main()   {       要点 t;       scanf("%d"、&t);       while(t-)       {           ドビー x 1,x 2,y 1,y 2,x 3,y 3,x 3,y 3,y           scanf("%lf%lf%lf%lf")、&x 1、&y 1、&x 2、&y 2);           x=x 2-x 1;           y=y 2-y 1;           x 3=x/2-y*sqrt(3)/2+x 1;           y 3=y/2+x*sqrt(3)/2+y 1;           printf('%2 f、%2 f)",x 3,y 3);       }       return 0;   )  http://www.cnblogs.com/E-star/archive/2013/06/11/3131563.html