メモ帳

楽しいアウトプットの場所

ABC197-D Opposite, 複素数の計算

atcoder.jp
p_0 = (x_0, y_0), p_{n/2}=(x_{n/2}, y_{n/2})
p_h = (\frac{x_0+x_{n/2}}{2}, \frac{y_0 + y_{n/2}}{2})=(x_h, y_h)
\alpha = \frac{2\pi}{n}
z_0 = x_0+iy_0
z_h=x_h+iy_h
t = (cos\alpha+i sin\alpha)
z_0-z_h = r(cos\theta+i sin\theta )
z_1 = (z_0-z_h)\times t+z_h =  r(cos(\theta+\alpha)+i sin(\theta+\alpha))+(x_h+iy_h)

from math import cos, sin, atan2
n = int(input())
x0, y0 = map(int, input().split())
x2, y2 = map(int, input().split())
xh = (x0+x2)/2
yh = (y0+y2)/2

r = ((x0-x2)**2+(y0-y2)**2)**0.5
r/=2

A = atan2((y0-yh), (x0-xh))
x = r*cos(A+(2*pi)/n)+xh
y = r*sin(A+(2*pi)/n)+yh

print(x, y)
from cmath import rect
from math import pi
n = int(input())
x0, y0 = map(int, input().split())
x2, y2 = map(int, input().split())

p0 = complex(x0, y0)
p2 = complex(x2, y2)

o = (p0+p2)/2
r = rect(1, 2*pi/n)
a = (p0-o)*r+o

print("%.10f %.10f"%(a.real, a.imag))