# Find the other end point of a line with given one end and mid

Given a midpoint of line(m1, m2) and one coordinate of a line (x1, y1), find the other end point(x2, y2) of a line

Examples:

Input : x1 = –1, y1 = 2, and m1 = 3, m2 = –6 Output : x2 = 7, y2 = 10 Input : x1 = 6.4, y1 = 3 and m1 = –10.7, m2 = 4 Output : x2 = 3, y2 = 4

The Midpoint Formula: The midpoint of two points, (x1, y2) and (x2, y2) is the point M found by using:

M=((x1+x2)/2, (y1+y2)/2),

We have need of a (x2, y2) so we modifies the formula

m1 = ((x1+x2)/2), m2 = ((y1+y2)/2) 2*m1 = (x1+x2), 2*m2 = (y1+y2) x2 = (2*m1 - x1), y2 = (2*m2 - y1)

## C++

`// CPP program to find the end point of a line ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// CPP function to find the end point of a line ` `void` `otherEndPoint(` `int` `x1, ` `int` `y1, ` `int` `m1, ` `int` `m2) ` `{ ` ` ` `// find end point for x cordinates ` ` ` `float` `x2 = (` `float` `)(2 * m1 - x1); ` ` ` ` ` `// find end point for y cordinates ` ` ` `float` `y2 = (` `float` `)(2 * m2 - y1); ` ` ` ` ` `cout << ` `"x2 = "` `<< x2 << ` `", "` ` ` `<< ` `"y2 = "` `<< y2; ` `} ` ` ` `// Driven Program ` `int` `main() ` `{ ` ` ` `int` `x1 = -4, y1 = -1, m1 = 3, m2 = 5; ` ` ` `otherEndPoint(x1, y1, m1, m2); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the end point of a line ` `class` `GFG { ` ` ` ` ` `// CPP function to find the end point ` ` ` `// of a line ` ` ` `static` `void` `otherEndPoint(` `int` `x1, ` `int` `y1, ` ` ` `int` `m1, ` `int` `m2) ` ` ` `{ ` ` ` `// find end point for x cordinates ` ` ` `float` `x2 = (` `float` `)(` `2` `* m1 - x1); ` ` ` ` ` `// find end point for y cordinates ` ` ` `float` `y2 = (` `float` `)(` `2` `* m2 - y1); ` ` ` ` ` `System.out.println(` `"x2 = "` `+ x2 + ` `", "` ` ` `+ ` `"y2 = "` `+ y2); ` ` ` `} ` ` ` ` ` `// Driven Program ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `x1 = -` `4` `, y1 = -` `1` `, m1 = ` `3` `, m2 = ` `5` `; ` ` ` `otherEndPoint(x1, y1, m1, m2); ` ` ` `} ` `} ` ` ` `// This code is contributed by JaideepPyne. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find the end ` `# point of a line ` ` ` `# function to find the end point ` `# of a line ` `def` `otherEndPoint(x1, y1, m1, m2): ` ` ` ` ` `# find end point for x cordinates ` ` ` `x2 ` `=` `(` `2` `*` `m1 ` `-` `x1) ` ` ` ` ` `# find end point for y cordinates ` ` ` `y2 ` `=` `(` `2` `*` `m2 ` `-` `y1) ` ` ` ` ` `print` `(` `"x2 = {}, y2 = {}"` ` ` `. ` `format` `(x2, y2)) ` ` ` `# Driven Program ` `x1 ` `=` `-` `4` `y1 ` `=` `-` `1` `m1 ` `=` `3` `m2 ` `=` `5` `otherEndPoint(x1, y1, m1, m2) ` ` ` `# This code is contributed by ` `# Manish Shaw (manishshaw1) ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the ` `// end point of a line ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// function to find the ` ` ` `// end pointof a line ` ` ` `static` `void` `otherEndPoint(` `int` `x1, ` `int` `y1, ` ` ` `int` `m1, ` `int` `m2) ` ` ` `{ ` ` ` ` ` `// find end point for x cordinates ` ` ` `float` `x2 = (` `float` `)(2 * m1 - x1); ` ` ` ` ` `// find end point for y cordinates ` ` ` `float` `y2 = (` `float` `)(2 * m2 - y1); ` ` ` ` ` `Console.WriteLine(` `"x2 = "` `+ x2 + ` `", "` ` ` `+ ` `"y2 = "` `+ y2); ` ` ` `} ` ` ` ` ` `// Driver Program ` ` ` `public` `static` `void` `Main(String []args) ` ` ` `{ ` ` ` `int` `x1 = -4, y1 = -1, m1 = 3, m2 = 5; ` ` ` `otherEndPoint(x1, y1, m1, m2); ` ` ` `} ` `} ` ` ` `// This code is contributed by nitin mittal. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// php program to find the end point of a line ` ` ` `// PHP function to find the end point of a line ` `function` `otherEndPoint(` `$x1` `, ` `$y1` `, ` `$m1` `, ` `$m2` `) ` `{ ` ` ` ` ` `// find end point for x cordinates ` ` ` `$x2` `= (2 * ` `$m1` `- ` `$x1` `); ` ` ` ` ` `// find end point for y cordinates ` ` ` `$y2` `= (2 * ` `$m2` `- ` `$y1` `); ` ` ` ` ` `echo` `"x2 = "` `. ` `$x2` `. ` `", y2 = "` `. ` `$y2` `; ` `} ` ` ` `// Driven Program ` ` ` `$x1` `= -4; ` `$y1` `= -1; ` `$m1` `= 3; ` `$m2` `= 5; ` ` ` `otherEndPoint(` `$x1` `, ` `$y1` `, ` `$m1` `, ` `$m2` `); ` ` ` `// This code is contributed by nitin mittal. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

x2 = 10, y2 = 11

## Recommended Posts:

- Program to find the mid-point of a line
- Find foot of perpendicular from a point in 2 D plane to a Line
- Find an Integer point on a line segment with given two ends
- Reflection of a point about a line in C++
- Perpendicular distance between a point and a Line in 2 D
- Direction of a Point from a Line Segment
- Check whether the point (x, y) lies on a given line
- Shortest distance between a Line and a Point in a 3-D plane
- Section formula (Point that divides a line in given ratio)
- Program to find slope of a line
- Program to find line passing through 2 Points
- Find points at a given distance on a line of given slope
- Find the Missing Point of Parallelogram
- Find Tangent at a given point on the curve
- Find normal at a given point on the curve

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.