# Find the Point

# Find the Point

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

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;

160216735012ECE + 1 comment this is complete code in c. logic: arithematic progression code:

#include<stdio.h> int main(void) { int n; scanf("%d",&n); int a[n][n],m[n]; for(int i=0;i<n;i++) { scanf("%d%d%d%d", &a[i][1], &a[i][2], &a[i][3],&a[i][4]); } for(int i=0;i<n;i++) { printf("%d %d\n",a[i][1]+2*(a[i][3]-a[i][1]),a[i][2]+2*(a[i][4]-a[i][2])); } return 0; }

160216735034ECE + 1 comment GOOD. it's working :-)

160216735012ECE + 0 comments thank you buddy

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;

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

Sort 171 Discussions, By:

Please Login in order to post a comment