# ARCHIPELAGO-SGU 120 (Calculate geometric vector rotation)

Source: Internet
Author: User

The main topic: there is a positive n-side shape, and then give two points, to find the coordinates of the remaining points.

Analysis: Vector rotation can be obtained coordinates, clockwise rotation time, x = X ' *cos (a) + y ' *sin (a), Y=-x ' *sin (a) + y ' *cos (a), counterclockwise x = X ' *cos (a)-Y ' *sin (a), Y=x ' *sin (a) +y ' *c OS (a). The topic first to seek out the center, and then ask for the remaining points, but the center of the time must pay attention to determine whether the angle is greater than pi two points.

The code is as follows:

==========================================================================================================

`#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;Const intMAXN =1007;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-7;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &tmp)Const{        returnPoint (x-tmp.x, ytmp.y); }    Double operator*(ConstPoint &tmp)Const{        returnx*tmp.x+y*tmp.y; }};DoubleDis (Point A, point B) {returnsqrt (A-B) * (Ab));}structsegment{Point S, e; Segment (Point S=0, point e=0): s (s), E (e) {} point Turn (DoubleLenDoublea) {///the coordinate of the line segment around the S-rotation a-angle after Len, clockwisePoint T = Es, ans; DoubleLen1 =Dis (S, e); ///printf ("sin (a) =%lf, cos (a) =%lf\n", Sin (a), cos (a));Ans.x = S.x + (T.y*sin (a) +t.x*cos (a)) *len/len1; Ans.y= S.y + (-t.x*sin (a) +t.y*cos (a)) *len/len1; returnans; }};intMain () {point P[MAXN]; intN, A, B; scanf ("%d%d%d", &n, &a, &B); A-=1, b-=1; scanf ("%LF%LF%LF%LF", &p[a].x, &p[a].y, &p[b].x, &p[b].y); if(A >b) Swap (A, B); DoubleA, B, R;    Segment L; if(B-a >= n/2)    {///angle greater than piA = PI *2/N; b= pi/2-A * (n (b-a))/2; L.s= P[b], L.E =P[a]; }    Else{a= PI *2/N; b= pi/2-A * (B-A)/2; L.s= P[a], L.E =P[b]; } R= Dis (L.S, L.E)/2/cos (b); Point Heart=L.turn (R, b); L.s=Heart;  for(intI=0; i<n; i++) {L.E= p[(a+i)%N]; p[(A+i+1)%N] =L.turn (R, a); }     for(intI=0; i<n; i++)    {        if(Fabs (p[i].x) <= EPS) p[i].x =EPS; if(Fabs (P[I].Y) <= EPS) P[i].y =EPS; printf ("%.6f%.6f\n", p[i].x+1e-Ten, p[i].y+1e-Ten); }    return 0;}`

Archipelago-sgu 120 (Calculate geometric vector rotation)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.