ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C语言求两直线夹角

2022-04-01 22:34:44  阅读:61  来源: 互联网

标签:直线 angle double C语言 k2 l2 l1 Line 夹角


#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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有