- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

In this problem, we are given the coordinates of two points of a line starting point A(x_{A}, y_{A}) and midpoint M(x_{M}, y_{M}) .Our task is to *find the other end point of a line with given one end and mid*.

**Let’s take an example to understand the problem,**

**Input**

A = [1, 2], M = [3, 0]

**Output**

[5, -2]

## Explanation

The line is −

## Solution Approach

To solve the problem, we will be using the concepts of geometry we have learned in mathematics. If you remember there is a midpoint formula for every line which is,

mid(x) = (x1 + x2) / 2 mid(y) = (y1 + y2) / 2

But we are given the value of the midpoint in the problem and need the value for x2 and y2. So, we will change the formula accordingly.

x2 = 2*mid(x) - x1 y2 = 2*mid(y) - y1

Using the above formula, we can find the value of the other endpoint using the midpoint and one point of the line.

## Example

Program to illustrate the working of our solution

#include <iostream> using namespace std; void findMissingPointLine(float x1, float y1, float xm, float ym){ float x2 = (2 * xm) - x1; float y2 = (2 * ym) - y1; cout<<"B(x, y) = "<<"( "<<x2<<", "<<y2<<" )"; } int main() { float x1 = -4, y1 = -1, xm = 3, ym = 5; cout<<"The other end point of the line is \n"; findMissingPointLine(x1, y1, xm, ym); return 0; }

## Output

The other end point of the line is B(x, y) = ( 10, 11 )

- Related Articles
- The length of a line segment is of 10 units and the coordinates of one end-point are $(2, -3)$. If the abscissa of the other end is 10, find the ordinate of the other end.
- C++ program to find out number of changes required to get from one end to other end in a grid
- The centre of a circle is $( -6, 4)$. If one end of the diameter of the circle is at $( -12, 8)$, then find the point of the other end.
- In Question 4, point ( mathrm{C} ) is called a mid-point of line segment ( mathrm{AB} ). Prove that every line segment has one and only one mid-point.
- Program to find the mid-point of a line in C++
- What is the mode of transfer of heat from one end of a metallic spoon to the other end ?
- Find the other-end coordinates of diameter in a circler in C++
- Swift Program to Find the Mid-point of a Line
- Append to StringBuilder in C# with a new line on the end
- Find the Kth Node from the end in a given singly Linked List using C++
- Count strings that end with the given pattern in C++
- What type of waves are illustrated by the movement of a rope whose one end is fixed to a pole and the other end is moved up and down?
- Mid-Point Line Generation Algorithm in C++
- How to match end of a particular string/line using Java RegEx
- Match optional end of line after every record with REGEXP?

Advertisements