用C++怎么求两直线的夹角

来源:百度知道 编辑:UC知道 时间:2024/05/13 10:39:26
已知直线1(x,y)和直线2(i,j) 怎样用程序求出他们的夹角
要详细点
是2D平面的

#include <iostream>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
main()
{
double x,y,z;
cout<<"请输入一个点的坐标 x y:";
cin>>x>>y;
z = atan(y/x)*180/PI;
if(x<0 && y>0)z+=90;
if(x<0 && y<=0)z+=180;
if(x>=0 && y<0)z+=360;
if(x!=0||y!=0) printf("夹角度数为:%.2f度\n",z);else
cout<<"不能输入原点..."<<endl;
}

真的不会吗

#include <iostream>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
main()
{
double x,y,z;
cout<<"请输入一个点的坐标 x y:";
cin>>x>>y;
z = atan(y/x)*180/PI;
if(x<0 && y>0)z+=90;
if(x<0 && y<=0)z+=180;
if(x>=0 && y<0)z+=360;
if(x!=0||y!=0) printf("夹角度数为:%.2f度\n",z);else
cout<<"不能输入原点..."<<endl;
}