# Find the Point

# Find the Point

bladekiller97 + 6 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; }

CrashWire + 1 comment Thank you for this information, highly helpful and I might've not done the challenge without this. Been many years without math. Took me a bit to get used to thinking again ^_^. You have my upvote.

utkarsh19972000 + 0 comments thanks for the help and logic i didnt able to understand the chellenge without your explenation

therawtechnoguy + 0 comments brilliant post, thank you for all the help

kapilesh_k23 + 0 comments You're a legend !

cervantes_lucas1 + 2 comments hi, can someone tell me what this means ? cin >> n

kapilesh_k23 + 0 comments taking n as an input, since this code is in C++

amirhamja0199211 + 0 comments It means that you are taking n as a input which represent number of set in this problem.

Hope you understand.

swaraliborde + 0 comments In case of their in-built c++ function where vector has to be returned, this code by me worked:

vector findPoint(int px, int py, int qx, int qy) {

`int rx=2*qx-px; int ry=2*qy-py; vector<int> v; v.push_back(rx); v.push_back(ry); return v;`

}

svworld01 + 0 comments I didn't understand the problem without reading your explanation..Thanks a lot

calcray96 + 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))

Altair007 + 2 comments hey, can u send me the complete solution . I am not able to import data. Thanks in advance.

linda_muemken + 0 comments That is the complete code. But i assume you try to use python3, there you have to change 'raw_input' into 'input', as this was renameD with python3.

pythonban + 0 comments Altair007, You dont need complete solution, coding is all about finding the solutions yourself, and a hint for solution: try section formula of co-ordinate geometry.

mkv_1724 + 0 comments python is beautiful language!

josef_klotzner + 0 comments Let me clarify please, that this solution might be simple for you, but it is definitly not a "simple" solution for a pyhton beginner. But it is a short solution and a clever solution, which needs quite some knowledge in python. I like it.

mrcoelho + 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.

abhiranjan + 3 comments Nope, you have to find another point such that (1, 1) lies in the middle of (0,0) and the new point.

mrcoelho + 1 comment After your comment I read it again and this time I got it. I don't know how I've could have missed that. I guess I was tired. Thanks mate!

sakshamnsit + 1 comment i did the same but not geeting the answer for testcase2

yadavsunil00001 + 0 comments dont forget to put endl after printing both number.

rajan_kr + 0 comments [deleted]kunnu120 + 0 comments Thanks abhiranjan, the question's not straightforward.

sanjaychandak + 0 comments it is just different as you interpret it. the language is quite wrong. in this question you have to find the 'r'. mean to say q is the symmetrical point of p & r.

selftaught91 + 0 comments All the three points should lie on the same line for symmetricity to happen.

sahil7459 + 0 comments hey you doesn't need to find the mid point but you can consider q as a mid point like p=(1,1) q=(5,5) and then you need to find the r with will be at equal distance from the q like as p is, and it would be 180 i.e. p,q,r must pe point of the same strainght line so r=(q1+(q1-p1), q2+(q2-p2))

i.e. r=(5+(5-1),5+(5-1))

abolisetti + 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)

coarang12 + 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;

Sort 225 Discussions, By:

Please Login in order to post a comment