其他分享
首页 > 其他分享> > C语言求两直线夹角

C语言求两直线夹角

作者:互联网

#include<math.h>
#include<stdio.h>
#define PI 3.14
typedef struct Point
{
    double x;
    double y;
}Point;

typedef struct Line
{
    Point a;
    Point b;
}Line;

double angle(Line l1,Line l2)
{
    double k1,k2;
    double angle;
    k1=(l1.a.y-l1.b.y)/(l1.a.x-l1.b.x);
    k2=(l2.a.y-l2.b.y)/(l2.a.x-l2.b.x);
    angle = atan(abs(k1-k2)/(1+k1*k2));
    return angle;
}
int main()
{
    Line l1,l2;
    l1.a.x=0;
    l1.a.y=0;
    l1.b.x=1;
    l1.b.y=1;
    l2.a.x=0;
    l2.a.y=0;
    l2.b.x=1;
    l2.b.y=0;
    printf("%f\n",angle(l1,l2)*180/PI);
    return 0;
}

 

标签:直线,angle,double,C语言,k2,l2,l1,Line,夹角
来源: https://www.cnblogs.com/EmbeddedChicken/p/16089469.html