# Find the Point

# Find the Point

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

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!

bladekiller97 + 2 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 + 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.

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

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.

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

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

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.

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.

dennindalke + 0 comments Minimalistic solution in Swift 4:

for _ in 1...Int(readLine()!)! { let line = readLine()!.split(separator:" ").map({Int($0)!}) print("\(2 * line[2] - line[0]) \(2 * line[3] - line[1])") }

dennindalke + 0 comments Minimalistic C# version:

using System.Linq; using static System.Console; class Solution { static void Main(string[] args) { for (int t = int.Parse(ReadLine()); t > 0; t--) { var ln = ReadLine().Split(' ').Select(int.Parse).ToArray(); WriteLine($"{2 * ln[2] - ln[0]} {2 * ln[3] - ln[1]}"); } } }

farti + 0 comments C#

int[] findPoint = new int[2]; findPoint[0]=(2*qx-px); findPoint[1]=(2*qy-py); return findPoint;

Sort 142 Discussions, By:

Please Login in order to post a comment