- Prepare
- Mathematics
- Fundamentals
- Find the Point
- Discussions

# Find the Point

# Find the Point

+ 13 comments The midPoint formula is the (first coordinate + second coordinate) divided by 2. So for example to find the mid-point between R(2, 2) and P(0, 0) you have to use the formula separately for X and Y. So the middle for X is (Mx = (Rx + Px) / 2 ) and for Y is (My = (Ry + Py) / 2)

Mx = (2 + 0) / 2 = 2 / 2 = 1

My = (2 + 0) / 2 = 2 / 2 = 1

so MidPoint is at coordinates M(1, 1).

What if the MidPoint is given and we have to calculate the point at the other half of the line. Then we use the formula above. So for example if we are given P(0, 0) and the midpoint M(1, 1) you should find R(x, y).

Mx = (Rx + Px) / 2 => Rx = 2Mx - Px

My = (Ry + Py) / 2 => Ry = 2My - Py

And thats how you find the coordinates for R. Here is my code :

#include <iostream> using namespace std; int main() { int n, px, py, mx, my; cin >> n; for (int i = 1; i <= n; i++){ cin >> px >> py >> mx >> my; int rx = 2 * mx - px; int ry = 2 * my - py; cout << rx << " " << ry << endl; } return 0; }

+ 3 comments Very simple in python.

for i in range(int(raw_input())): px, py, qx, qy = map(int, raw_input().split()) print ("{0} {1}".format(2*qx-px, 2*qy-py))

+ 4 comments Hey guys, I hope you could help me out understanding the problem. From what I understand, the problem is to find the midpoint of a line (or two points). However, I do not understand the output of the given example. How can (2, 2) be the midpoint of (0, 0) and (1, 1)? Shouldn't it be (1/2, 1/2). I guess missing something, but I can't figure it out.

+ 0 comments here is solution for c#

int[] values = new int[2]; int rx = qx - px + qx, ry = qy - py + qy; values[0] = rx; values[1] = ry; return values;

+ 0 comments python is bless

for i in range(int(input())): x1,y1,x2,y2 = (map(int, input().split())) print(x1+(x2-x1)*2, y1+(y2-y1)*2)

Sort 317 Discussions, By:

Please Login in order to post a comment