1.13. Reflection Point 2

Given two points P(px,py) and Q(qx,qy) in the two-dimensional plane, we name the point that is in the middle of the two points the mid point, M(mx,my), and the point that is the 180° rotation of P around Q the reflection point, R(rx,ry).

Consider the following case:

image1

Given P(1,1) and Q(3,3), we say the mid point M is M(2,2) and the reflection point R is R(5,5). It can be seen from the figure that, Q is the mid-point of P and R, so the distance from P to Q and the distance from Q to R are the same.

Write a program that takes 4 integers as input from the user, the coordinates of P and Q (in the order :math:`p_x, p_y, q_x, q_y`), and prints their mid point and the reflection point in the order mx,my,rx,ry as floats with 2 digits after the decimal point.

Sample I/O:

Input:
1
1
3
3

Output:
2.00
2.00
5.00
5.00

Input:
-1
-1
1
1

Output:
0.00
0.00
3.00
3.00

Input:
4
5
1
2

Output:
2.50
3.50
-2.00
-1.00
Copy to clipboard
px = int(input())
py = int(input())
qx = int(input())
qy = int(input())

mx = (px + qx) / 2
my = (py + qy)/2

rx = qx + (qx - px)
ry = qy + (qy - py)

print("{:.2f}".format(mx))
print("{:.2f}".format(my))
print("{:.2f}".format(rx))
print("{:.2f}".format(ry))
Copy to clipboard