Angle between two Planes in 3D in C++?


For learning about the angle between two planes in 3D, we need to learn about planes and angles.

Plane is a two-dimensional surface that extends to infinity.

Angle is the space in degrees between two lines and surfaces which intersect at a point.

So, in this problem we need to find the angle between two 3D planes. For this we have two planes that intersect each other and we need to find the angle at which the are intersecting each other.

To calculate the angle between two 3D planes, we need to calculate the angle between the normal's of these planes.

Here, we have two planes,

p1 : ax + by + cz + d = 0
p2 : hx + iy + j z + k = 0

The directions of the normal's of the planes p1 and p2 are (a,b,c) and (h,i,j).

Using this a mathematical formula that is created to find the angle between the normal's of these two planes is,

Cos Ø = {(a*h) + (b*i) + (c*j)} / [(a2 + b2 + c2)*(h2 + i2 + j2)]1/2
Ø = Cos-1 { {(a*h) + (b*i) + (c*j)} / [(a2 + b2 + c2)*(h2 + i2 + j2)]1/2 }

Example

 Live Demo

#include <iostream>
#include <math.h>
using namespace std;
int main() {
   float a = 2;
   float b = 2;
   float c = -1;
   float d = -5;
   float h = 3;
   float i = -3;
   float j = 5;
   float k = -3;
   float s = (a*h + b*i + c*j);
   float t = sqrt(a*a + b*b + c*c);
   float u = sqrt(h*h + i*i + j*j);
   s = s / (t * u);
   float pi = 3.14159;
   float A = (180 / pi) * (acos(s));
   cout<<"Angle is "<<A<<" degree";
   return 0;
}

Output

Angle is 104.724 degree

Updated on: 04-Oct-2019

173 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements