# Find the Point

# Find the Point

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

- NS
Altair007 + 1 comment hey, can u send me the complete solution . I am not able to import data. Thanks in advance.

- LM
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.

mkv_1724 + 0 comments python is beautiful language!

- M
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.

- M
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!

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

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

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

- SC
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))

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

- JC
CrashWire + 0 comments 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.

- AB
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)

edlaierii + 0 comments What the what??? I cannot use the C# Point class from either System.Drawing or System.Windows. Well shucks!

- SP
satyam_pandey + 1 comment Its just mid-point formula . [(x_1 + x_2)/2 , (y_1 + y_2)/2]

but instead of finding mid point we have find x2 and y2

import java.io.

*; import java.util.*;public class Solution {

`public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); int test_case = scan.nextInt(); for(int i=0;i<test_case;i++){ int x1 = scan.nextInt(); int y1 = scan.nextInt(); int x2 = scan.nextInt(); int y2 = scan.nextInt(); findNextPoint(x1,x2,y1,y2); } } private static void findNextPoint(int x1, int x2, int y1, int y2) { // TODO Auto-generated method stub int x, y; x= 2*x2 - x1; y = 2*y2 - y1; System.out.println(x +" "+y); }`

}

JulioLeme + 1 comment Congratulations, here is one more solution in Java a little more clean...

public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) { int px = sc.nextInt(), py = sc.nextInt(), qx = sc.nextInt(), qy = sc.nextInt(), pe = 2*qx - px, pe2 = 2*qy - py; System.out.println(pe + " " +pe2); }

}ashfaqzp + 0 comments pe = 2*qx - px, pe2 = 2*qy - py It is returning 0 0

pulkit65sinha + 1 comment It is basically the mid point formula that we are using.But the problem I have encountered is the test case fails even when the expected output matches with my output.

- DB
ankushk456 + 0 comments Make a thorough check that there are no extra white spaces as compared to the output format. Do check if all the conditions are met.

- RS
rajlovestokyo + 0 comments static int[] findPoint(int px, int py, int qx, int qy) { /* * Write your code here. */ int r[] = new int[2]; r[0] = 2*qx -px; r[1] = 2*qy -py; return r; }

- AD
the_new_guy + 0 comments vector<int> findPoint(int px, int py, int qx, int qy) { int rx,ry; rx = qx*2 - px; ry = qy*2 - py; int r[2]; r[0] = rx; r[1] = ry; return r; }

help please ! I can't seem to return a vector !

- DO
Odvin + 0 comments q is the middle point

def findPoint(px, py, qx, qy): return 2*qx - px, 2*qy - py

Sort 127 Discussions, By:

Please Login in order to post a comment