设两直线夹角为θ,l1的倾角为α,l2的倾角为β.
则:tanα=( y2-y2 )/( x2-x1 ) tanβ=( y4-y3 )/( x4-x3 )
根据两直线夹角公式得:
tanθ= ( | tanα-tanβ | ) / ( 1 + tanα*tanβ )
所以
θ = arc tan[( | tanα-tanβ | ) / ( 1 + tanα*tanβ )]
最后分别把 tanα , tanβ 代入.
下附一段测试代码:
#include <math.h> #include <stdio.h> //编写:GUO (QQ:349384061) void main( void ) { double pi = 3.1415926535; double tan1,tan2; double tan3,angle; tan1 = tan(pi * 30 / 180); tan2 = tan(pi * 120 / 180); tan3 = fabs(tan1 - tan2) / (1 + tan1 * tan2); angle = atan(tan3) / pi * 180; printf("tan1:%f ",tan1); printf("tan2:%f ",tan2); printf("tan3:%f ",tan3); printf("angle:%f ",angle); }