[AtCoder] ABC 197 D – Opposite

問題

方針

\( N = 2n \) とします。点 \( p_0 \) と 点 \( p_{n} \) を結ぶ線は正 \( N \) 角形の重心である

\[ \left(\dfrac{x_0 + x_n}{2}, \dfrac{y_0 + y_n}{2} \right)\]

を通ります。したがって、この重心を中心として点 \( p_0 \) を \( \frac{360}{N} \) 度回転させたものが \( p_1 \) となります。

コード

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    double x, y, X, Y;
    cin >> x >> y >> X >> Y;
    double dx = X - x;
    double dy = Y - y;
    double r = sqrt(dx * dx + dy * dy);
    double th = (double) 360 / N * acos(-1) / 180.0;
    double x0 = x - (x + X) / 2;
    double y0 = y - (y + Y) / 2;
    double x1 = cos(th) * x0 - sin(th) * y0;
    double y1 = sin(th) * x0 + cos(th) * y0;
    cout << x1 + (x + X) / 2 << " " << y1 + (y + Y) / 2 << "\n";
    return 0;
}