Angle between two Planes in 3D in C Program?

In 3D geometry, planes are flat surfaces extending infinitely in space. When two planes intersect, they form a line, and the angle between them becomes an important geometric measure. The angle between two planes is calculated using their normal vectors and the dot product formula.

Syntax

angle = acos(dot_product / (magnitude1 * magnitude2)) * (180 / PI)

Plane Equations

Two planes in 3D space can be represented by the following general equations −

P1: a1 * x + b1 * y + c1 * z + d1 = 0  
P2: a2 * x + b2 * y + c2 * z + d2 = 0

Here, (a1, b1, c1) and (a2, b2, c2) are the direction ratios of the normal vectors to planes P1 and P2, respectively.

Plane 1 Plane 2 n? n? ? Intersection Line

Mathematical Formula

The angle between two planes is the same as the angle between their normal vectors. This angle can be calculated using the dot product formula

cos(?) = (a1*a2 + b1*b2 + c1*c2) / (?(a1² + b1² + c1²) * ?(a2² + b2² + c2²))
? = arccos(cos(?)) * (180/?)

Example

Let's calculate the angle between two planes with the following equations −

Input: a1 = 1, b1 = 1, c1 = 2, d1 = 1, a2 = 2, b2 = -1, c2 = 1, d2 = -4
Plane 1: 1x + 1y + 2z + 1 = 0 ? Normal vector n? = (1, 1, 2)
Plane 2: 2x - 1y + 1z - 4 = 0 ? Normal vector n? = (2, -1, 1)

cos(?) = (1*2 + 1*(-1) + 2*1) / (?(1² + 1² + 2²) * ?(2² + (-1)² + 1²))
cos(?) = (2 - 1 + 2) / (?6 * ?6)
cos(?) = 3/6 = 0.5
? = arccos(0.5) = 60°
#include <stdio.h>
#include <math.h>

void calculateAngle(float a1, float b1, float c1, float a2, float b2, float c2) {
    // Calculate dot product of normal vectors
    float dotProduct = (a1 * a2 + b1 * b2 + c1 * c2);
    
    // Calculate magnitudes of normal vectors
    float magnitude1 = sqrt(a1 * a1 + b1 * b1 + c1 * c1);
    float magnitude2 = sqrt(a2 * a2 + b2 * b2 + c2 * c2);
    
    // Calculate cosine of angle
    float cosTheta = dotProduct / (magnitude1 * magnitude2);
    
    // Calculate angle in degrees
    float angleRadians = acos(cosTheta);
    float angleDegrees = angleRadians * (180.0 / M_PI);
    
    printf("Angle between the planes = %.1f degrees<br>", angleDegrees);
}

int main() {
    // Coefficients of plane 1: x + y + 2z + 1 = 0
    float a1 = 1, b1 = 1, c1 = 2;
    
    // Coefficients of plane 2: 2x - y + z - 4 = 0
    float a2 = 2, b2 = -1, c2 = 1;
    
    printf("Plane 1: %.0fx + %.0fy + %.0fz + 1 = 0<br>", a1, b1, c1);
    printf("Plane 2: %.0fx + %.0fy + %.0fz - 4 = 0<br>", a2, b2, c2);
    
    calculateAngle(a1, b1, c1, a2, b2, c2);
    
    return 0;
}
Plane 1: 1x + 1y + 2z + 1 = 0
Plane 2: 2x + -1y + 1z - 4 = 0
Angle between the planes = 60.0 degrees

Key Points

  • The angle between two planes equals the angle between their normal vectors.
  • Use the dot product formula: cos(?) = (n? · n?) / (|n?| × |n?|)
  • The result from acos() is in radians − multiply by 180/? to convert to degrees.
  • Normal vectors are extracted from plane coefficients: (a, b, c) from ax + by + cz + d = 0.

Conclusion

Finding the angle between two planes in 3D space involves calculating the angle between their normal vectors using the dot product formula. This method provides an efficient way to determine geometric relationships in three−dimensional space.

Updated on: 2026-03-15T11:45:00+05:30

281 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements