A. 高分求 編程 c語言 已知2點求角度
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pi 3.1415926
struct point
{
double X;
double Y;
};
struct line
{
point A;
point B;
double deg;
};
int main( )
{
line lineA;
line lineB;
double tmp;
printf("請輸點坐標(x,y)構造第一條直線\n");
printf("第一點x與y:");
scanf( "%lf%lf", &lineA.A.X, &lineA.A.Y );
printf("第二點x與y:");
scanf( "%lf%lf", &lineA.B.X, &lineA.B.Y );
//求角度
tmp=(lineA.B.Y-lineA.A.Y)/(lineA.B.X-lineA.A.X);
lineA.deg=atan(tmp);
lineA.deg=lineA.deg*double(180)/pi;
printf( "第一條直線斜線角度:%lf,%lf\n", tmp,lineA.deg );
printf("請輸點坐標(x,y)構造第二條直線\n");
printf("第一點x與y:");
scanf( "%lf%lf", &lineB.A.X, &lineB.A.Y );
printf("第二點x與y:");
scanf( "%lf%lf", &lineB.B.X, &lineB.B.Y );
//求角度
tmp=(lineB.B.Y-lineB.A.Y)/(lineB.B.X-lineB.A.X);
lineB.deg=atan(tmp);
lineB.deg=lineB.deg*double(180)/pi;
printf( "第二條直線斜線角度:%lf,%lf\n", tmp,lineB.deg );
printf( "兩條直線角度差:%lf\n", lineA.deg-lineB.deg );
return 0;
}
/*
atan等三角函數算出來的是pi形式的,看看45度的:
printf("%f\n",tan(double(45)/double(180)*pi));
printf("%f\n",atan(1)*double(180)/pi);
寫的真累,看你題目是C語言,所以沒用C++類來寫
用類來寫,又好寫,又好讀,又不容易出錯
point點(x,y)其實可以直接用COORD,又怕你沒有數據結構COORD
比如:
struct line
{
point A;
point B;
double deg;
};
改成
struct line
{
COORD dian; //COORD編譯器數據結構dian有dian.X和dian.Y
double deg;
};
*/
B. 用C語言編寫程序,判斷輸入的二維點在第幾象限(易懂的)
if(xy>0)
{
if(x>0)
printf("第一象限");
else
printf("第三象限");
}
else if(xy<0)
{
if(x>0)
printf("第二象限");
else
printf("第四象限");
}
else
printf("坐標軸上");
C. 大哥 坐標反算後的結果與象限角是什麼關系 又怎樣把反算的結果換算成正確的坐標方位角哪
設反算的結果為a,a=arctan(dy/dx),其中dy=y2-y1,dx=x2-x1.
若dy>0,dx>0,說明角在第一象限,坐標方位角b=a.
若dy<0,dx>0,說明角在第二象限,坐標方位角b=a+180.
若dy<0,dx<0,說明角在第三象限,坐標方位角b=a+180.
若dy>0,dx<0,說明角在第四象限,坐標方位角b=a+360.
D. 編程 輸入一平面坐標點(x,y),判斷並輸出該坐標點位於哪個象限c語言
#include<stdio.h>
int x,y;
char *output[20];
int p;
void main(){
printf("請輸入一個坐標如:3,3\n");
while(scanf("%d,%d",&x,&y)!=EOF)
{
if(x > 0 && y > 0)
p=1;
else if(x > 0 && y < 0)
p=4;
else if(x < 0 && y > 0)
p=2;
else if(x < 0 && y < 0)
p=3;
switch(p){
case 1:*output = "第一象限\n";break;
case 4:*output = "第四象限\n";break;
case 2:*output = "第二象限\n";break;
case 3:*output = "第三象限\n";break;
}
printf("%s",*output);
}
}