- 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 coordinates of the triangle given midpoint of each side in C++
Suppose we have three coordinates which are midpoint of sides of the triangle. We have to find the coordinates of the triangle. So if the inputs are like (5, 3), (4, 4), (5, 5), then output will be (4, 2), (4, 6), (6, 4).
To solve this, we have to solve for X-coordinates and Y-coordinates separately. For X coordinate of vertices, let them be x1, x2, x3. Then, X-coordinate of middle points will be (x1 + x2)/2, (x2 + x3)/2, (x3 + x1)/2. If we observe the sum of these three expressions is equal to sum of X-coordinates. Now, we have sum of three variables and three expressions for sum of every pair of them. We have to find out the values of coordinates by solving equations. Similarly, we solve for Y-coordinates.
Example
#include<iostream> #include<vector> #define N 3 using namespace std; vector<int> getResult(int v[]) { vector<int> res; int sum = v[0] + v[1] + v[2]; res.push_back(sum - v[1]*2); res.push_back(sum - v[2]*2); res.push_back(sum - v[0]*2); return res; } void searchPoints(int mid_x_coord[], int mid_y_coord[]) { vector<int> x_vals = getResult(mid_x_coord); vector<int> y_vals = getResult(mid_y_coord); for (int i = 0; i < 3; i++) cout << x_vals[i] << " " << y_vals[i] <<endl; } int main() { int mid_x_coord[N] = { 5, 4, 5 }; int mid_y_coord[N] = { 3, 4, 5 }; searchPoints(mid_x_coord, mid_y_coord); }
Output
6 4 4 2 4 6
- Related Articles
- Each of the 2 equal sides of an isosceles triangle is twice as large as the third side. If the perimeter of the triangle is 30 cm. Find the length of each side of the triangle.
- ABC is an equilateral triangle of side $2a$. Find each of its altitudes.
- Two equal side of a triangle are each 4m less than three times the third side. Find the side of the triangle if it's perimeter is 55 m
- Find minimum area of rectangle with given set of coordinates in C++
- The perimeter of an isosceles triangle is 28 cm. The unequal side is 10 cm. Find the length of each equal side.
- The sides of a triangle are in the ratio of 2:3:4. If the perimeter of the triangle is 45 CM, find the length of each side of the triangle.
- Draw the graph of each of the equations given below. Also, find the coordinates of the points where the graph cuts the coordinates axes:$6x – 3y = 12$
- Draw the graph of each of the equations given below. Also, find the coordinates of the points where the graph cuts the coordinates axes:$-x + 4y = 8$
- Draw the graph of each of the equations given below. Also, find the coordinates of the points where the graph cuts the coordinates axes:$2x + y = 6$
- The perimeter of an isosceles triangle is $42 cm$ and its base is ($frac{3}{2}) times each of the equal sides. Find the length of each side of the triangle, area of the triangle and the height of the triangle.
- Draw the graph of each of the equations given below. Also, find the coordinates of the points where the graph cuts the coordinates axes:$3x + 2y + 6 = 0$
- Find the base of given triangle."
- How To Find the Midpoint of a Line in Java?
- If $(-4, 3)$ and $(4, 3)$ are two vertices of an equilateral triangle, find the coordinates of the third vertex, given that the origin lies in the interior of the triangle.
- If $(-4, 3)$ and $(4, 3)$ are two vertices of an equilateral triangle, find the coordinates of the third vertex, given that the origin lies in the exterior of the triangle.

Advertisements