C语言编程求助!
发布网友
发布时间:2023-05-18 01:51
我来回答
共1个回答
热心网友
时间:2023-09-19 19:45
#include<math.h>
#include<stdio.h>
int main(){
const double PI=3.1415926535;
double x1,y1,h1;
double x2,y2,h2;
double x3,y3,h3;
printf("请输入A点的X,Y,H用逗号隔开:\n");
scanf("%lf,%lf,%lf",&x1,&y1,&h1);
printf("请输入B点的X,Y,H用逗号隔开:\n");
scanf("%lf,%lf,%lf",&x2,&y2,&h2);
printf("请输入C点的X,Y,H用逗号隔开:\n");
scanf("%lf,%lf,%lf",&x3,&y3,&h3);
double ax=(y2-y1)(h3-h1)-(h2-h1)(y3-y1);
double ay=(h2-h1)(x3-x1)-(x2-x1)(h3-h1);
double az=(x2-x1)(y3-y1)-(y2-y1)(x3-x1);
double theta=acos(az/sqrt(ax*ax+ay*ay+az*az));
if(az<0){
theta=PI-theta;
}
double epsilon=acos(fabs(ay)/sqrt(ax*ax+ay*ay));
if(ax>=0){ //ax>=0
if(ay>=0)
beta=epsilon; //ax>=0,ay>=0
else
beta=2*PI-epsilon; //ax>=0,ay<0
}else{ //ax<0
if(ay>=0)
beta=PI-epsilon; //ax<0,ay>=0
else
beta=PI+epsilon; //ax<0,ay<0
}
theta=theta*180/PI; //radian to degree
beta=beta*180/PI; //radian to degree
printf("theta=%lf,beta=%lf\n",theta,beta);
return 0;
}