
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to check whether points in a 3-D plane are Coplanar
Given with the points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) and (x4, y4, z4) and the program must check whether the given points are coplanar or not. Points are said to be coplanar is they lie under same plane and if they are under different-2 planes than the points are not coplanar.
Given below is an image containing four points and all are under same plane which is xy plane that means points are coplanar
Given below is an image containing four points and all are under different planes which shows points are not coplanar
Example
Input-: x1 = 2, y1 = 3, z1 = 1, x2 = 1, y2 = 9, z2 = 3, x3 = 3, y3 = 1, z3 = 5, x4 = 23, y4 = 21, z4 = 9 Output-: they are not coplanar Input-: x1 = 3, y1 = 2, z1 = -5, x2 = -1, y2 = 4, z2 = -3, x3 = -3, y3 = 8, z3 = -5, x4 = -3, y4 = 2, z4 = 1 Output-: they are coplanar
Approach used in the below program is as follows −
- Input the points in the variables (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) and (x4, y4, z4)
- Find the equations of the plane and check whether they are satisfying the conditions or not
- Display whether the points are coplanar or not
ALGORITHM
START Step 1-> declare function to check whether points in 3-D are coplanar or not void check_coplanar(int x1,int y1,int z1,int x2,int y2,int z2, int x3, int y3, int z3, int x, int y, int z) declare variable as int a1 = x2 - x1 declare variable as int b1 = y2 - y1 declare variable as int c1 = z2 - z1 declare variable as int a2 = x3 - x1 declare variable as int b2 = y3 - y1 declare variable as int c2 = z3 - z1 declare variable as int a = b1 * c2 - b2 * c1 declare variable as int b = a2 * c1 - a1 * c2 declare variable as int c = a1 * b2 - b1 * a2 declare variable as int d = (- a * x1 - b * y1 - c * z1) check IF(a * x + b * y + c * z + d = 0) print coplanar End Else print not coplanar End Step 2-> In main() declare and set variable int x1 = 2 , y1 = 3, z1 = 1, x2 = 1, y2 = 9, z2 = 3, x3 = 3, y3 = 1, z3 = 5, x4 = 23, y4 = 21, z4 = 9 call check_coplanar(x1, y1, z1, x2, y2, z2, x3,y3, z3, x4, y4, z4) STOP
Example
#include<bits/stdc++.h> using namespace std ; //calculate points in a plane are coplanar or not void check_coplanar(int x1,int y1,int z1,int x2,int y2,int z2, int x3, int y3, int z3, int x, int y, int z) { int a1 = x2 - x1 ; int b1 = y2 - y1 ; int c1 = z2 - z1 ; int a2 = x3 - x1 ; int b2 = y3 - y1 ; int c2 = z3 - z1 ; int a = b1 * c2 - b2 * c1 ; int b = a2 * c1 - a1 * c2 ; int c = a1 * b2 - b1 * a2 ; int d = (- a * x1 - b * y1 - c * z1) ; if(a * x + b * y + c * z + d == 0) cout << "they are coplanar" << endl; else cout << "they are not coplanar" << endl; } int main() { int x1 = 2; int y1 = 3 ; int z1 = 1 ; int x2 = 1 ; int y2 = 9 ; int z2 = 3 ; int x3 = 3 ; int y3 = 1 ; int z3 = 5 ; int x4 = 23 ; int y4 = 21 ; int z4 = 9 ; check_coplanar(x1, y1, z1, x2, y2, z2, x3,y3, z3, x4, y4, z4) ; return 0; }
Output
If run the above code it will generate the following output -
they are not coplanar
- Related Articles
- Program to find equation of a plane passing through 3 points in C++
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Program to check if three points are collinear in C++
- Program to check whether list of points form a straight line or not in Python
- C# program to check whether two sequences are the same or not
- Program to check whether String Halves Are Alike in Python
- C# Program to check whether a directory exists or not
- C++ Program to Check Whether Graph is DAG
- Program to check whether given words are maintaining given pattern or not in C++
- Program to check whether a string is subsequence of other in C++
- Python Program to check whether all elements in a string list are numeric
- Finding distance between two points in a 2-D plane using JavaScript
- Program to check whether parentheses are balanced or not in Python
- C# program to check whether a list is empty or not
- C++ Program to Check Whether a Number is Prime or Not

Advertisements