 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 all possible coordinates of parallelogram in C++
Find the all of the possible coordinates from the given three coordinates to make e parallelogram of a non-zero area. Suppose A, B, C are three given points we can have only three possible situations.
- AB, AC are sides, and BC is diagonal
- AB, BC are sides, and AC is diagonal
- BC, AC are sides, and AB is diagonal
So we can say that only three coordinates are possible, from which we can generate a parallelogram, if three coordinates are given. Since the opposite sides are equal, then AD = BC, and AB = CD, we will calculate the coordinate of the missing points D like below −
(Dx-Ax,Dy-Ay) = (Cx-Bx,Cy-By) Dx = Ax+Cx-Bx Dy = Ay+Cy-By
Example
#include<iostream> using namespace std; void printPoints(int ax, int ay, int bx, int by, int cx, int cy){    cout << ax + bx - cx << ", " << ay + by - cy <<endl;    cout << ax + cx - bx << ", " << ay + cy - by <<endl;    cout << cx + bx - ax << ", " << cy + by - ax <<endl; } int main() {    int ax = 5, ay = 0; //coordinates of A    int bx = 1, by = 1; //coordinates of B    int cx = 2, cy = 5; //coordinates of C    printPoints(ax, ay, bx, by, cx, cy); }  Output
4, -4 6, 4 -2, 1
Advertisements
 