用c语言编写钟表指针角度(高分求 编程 c语言 已知2点求角度)

本文目录
高分求 编程 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;
};
*/
谁能帮我用c语言编写桌面钟表啊!
#include《math.h》
#include《dos.h》
#include《graphics.h》
#define CENTERX 320 /*表盘中心位置*/
#define CENTERY 175
#define CLICK 100 /*喀嗒声频率*/
#define CLICKDELAY 30 /*喀嗒声延时*/
#define HEBEEP 10000 /*高声频率*/
#define LOWBEEP 500 /*低声频率*/
#define BEEPDELAY 200 /*报时声延时*/
/*表盘刻度形状*/
int Mrk_1={-5,-160,5,-160,5,-130,-5,-130, };
int Mrk_2={-5,-160,5,-160,2,-130,-2-130, };
/*时针形状*/
int HourHand={-3,-100,3,-120,4, 10,-4,10};
/*分针形状*/
int MiHand={-3,-120,3,-120,4, 10,-4,10};
/*秒针形状*/
int SecHand={-2,-150,2,-150,3, 10,-3,10};
/*发出喀嗒声*/
void Click()
{
sound(CLICK);
delay(CLICKDELAY);
nosound();
}
/*高声报时*/
void HighBeep()
{
sound(HEBEEP);
delay(BEEPDELAY);
nosound;
}
/*低声报时*/
void LowBeep()
{
sound(LOWBEEP);
}
/*按任意角度画多边形*/
void DrawPoly(int *data,int angle,int color)
{
int usedata;
float sinang,cosang;
int i;
sinang=sin((float)angle/180*3.14);
cosang=cos((float)angle/180*3.14);
for(i=0;i《8;i+=2)
{
usedata+.5;
usedata+.5;
}
setfillstyle(SOLID_FILL,color);
fillpoly(4,usedata);
}
/*画表盘*/
void DrawClock(struct time *cutime)
{
int ang;
float hourrate,minrate,secrate;
setbkcolor(BLUE);
cleardevice();
setcolor(WHITE);
/* 画刻度*/
for(ang=0;ang《360;ang+=90)
{
DrawPoly(Mrk_1,ang,WHITE);
DrawPoly(Mrk_2,ang+30,WHITE);
DrawPoly(Mrk_2,ang+60,WHITE);
}
secrate=(float)cutime-》ti_sec/60;
minrate=((float)cutime-》ti_min+secrate)/60;
hourrate=(((float)cutime-》ti_hour/12)+minrate)/12;
ang=hourrate*360;
DrawPoly(HourHand,ang,YELLOW);/*画时针*/
ang=minrate*360;
DrawPoly(MiHand,ang, GREEN);/*画分针*/
ang=secrate*360;
DrawPoly(SecHand,ang, RED);/*画秒针*/
}
main()
{
int gdriver=EGA,
gmode=EGAHI;
int curpage;
struct time curtime ,newtime ;
initgraph(&gdriver,&gmode,"c:\\tc");
setbkcolor(BLUE);
cleardevice();
gettime(&curtime);
curpage=0;
DrawClock(&curtime);
while(1)
{
if(kbhit())
break; /*按任意键退出*/
gettime(&newtime); /*检测系统时间*/
if(newtime.ti_sec!=curtime.ti_sec)/*每1秒更新一次时间*/
{
if(curpage==0)
curpage=1;
else
curpage=0;
curtime=newtime;
/*设置绘图页*/
setactivepage(curpage);
/*在图页上画表盘*/
DrawClock(&curtime);
/*设置绘图页为当前可见页*/
setvisualpage(curpage);
/*0分0秒高声报时*/
if(newtime.ti_min==0&&newtime.ti_sec==0)
HighBeep();
/* 59分55至秒时低声报时*/
else if(newtime.ti_min==59&&
newtime.ti_sec《=59)
LowBeep();/*其他时间只发出喀嗒声*/
else
Click();
}
}
closegraph();
}
在c语言里怎么办输入的弧度制转化为角度值
(1)没有 °符号的都是弧度制,换句话说,角度制一定有 °
(2)在高中数学中,若没有特殊说明,都习惯用弧度制表示,弧度和角度的转换式为
角度=(180°/π)*弧度
c语言源代码如下:
#include 《stdio.h》
#include 《stdlib.h》
int main(int argc, char*argv)
{
const double pi=3.14159;
int jd; //角度值
double hd; //弧度值
printf("请输入角度值:\n");
scanf("%d",&jd);
hd=jd*pi/180;
printf("对应的弧度值:%g\n",hd);
system("pause");
return 0;
}
C语言编图形时钟
给你2个选吧,都是原创:
第1个:
#include《graphics.h》
#include《math.h》
#include《dos.h》
#define pi 3.1415926
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)
void init()
{int i,l,x1,x2,y1,y2;
setbkcolor(1);
circle(300,240,200);
circle(300,240,205);
circle(300,240,5);
for(i=0;i《60;i++)
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s;
struct time t;
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t.ti_hour;
m=t.ti_min;
s=t.ti_sec;
setcolor(7);
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit())
{while(t.ti_sec==s)
gettime(t);
sound(400);
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t.ti_sec;
d(190,s,6);
if (t.ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t.ti_min;
d(170,m,6);
}
if (t.ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t.ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch();
closegraph();
}
第2个:
#include《graphics.h》
#include《math.h》
#include《dos.h》
#define PI 3.1415926
#define x0 320 /*定义钟表中心坐标*/
#define y0 240
void DrawClock(int x,int y,int color) /*画表盘*/
{ int r=150; /*表盘的半径*/
float th;
setcolor(color);
circle(x,y,r);
circle(x,y,2);
}
void DrawHand(int x,int y,float th,int l,int color)
{
int x1,y1;
x1=x+l*sin(th);
y1=y-l*cos(th);
setcolor(color);
line(x,y,x1,y1);
}
void main()
{int gdriver=DETECT,gmode;
struct time curtime;
float th_hour,th_min,th_sec;
initgraph(&gdriver,&gmode,"");
setbkcolor(0);
while(! kbhit())
{
DrawClock(x0,y0,14);
gettime(&curtime); /*得到当前系统时间*/
gotoxy(35,20); /*定位输出位置*/
if((float)curtime.ti_hour《=12) /*午前的处理*/
{printf("AM ");
if((float)curtime.ti_hour《10) printf("0"); /*十点之前在小时数前加零*/
printf("%.0f:",(float)curtime.ti_hour);
}
else /*午后的处理*/
{printf("PM ");
if((float)curtime.ti_hour-12《10) printf("0");
printf("%.0f:",(float)curtime.ti_hour-12);
}
if((float)curtime.ti_min《10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec《10) printf("0");
printf("%.0f",(float)curtime.ti_sec);
/*以下三行计算表针转动角度,以竖直向上为起点,顺时针为正*/
th_sec=(float)curtime.ti_sec*0.1047197551; /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0; /* 2π/12=0.5235987755 */
DrawHand(x0,y0,th_hour,70,2); /*画时针*/
DrawHand(x0,y0,th_min,110,3); /*分针*/
DrawHand(x0,y0,th_sec,140,12); /*秒针*/
sleep(1); /*延时一秒后刷新*/
cleardevice();
}
closegraph();
}
c语言角度转弧度和弧度转角度分别应该怎么编写
角度转弧度: π/180×角度 ;弧度变角度:180/π×弧度
实现代码如下:
#include《stdio.h》
#define PI 3.14159265f
void main(){
int x;
float y;
printf("角度转弧度请按5,弧度转角度请按6\n");
scanf("%d",&x);
switch(x) {
case 5:
printf("输入角度:");
scanf("%f",&y);
printf("弧度为:%f\n",(y/180)*PI);
break;
case 6:
printf("输入弧度:");
scanf("%f",&y);
printf("角度为:%f\n",(y/PI)*180);
}
}
扩展资料:
角度和弧度
数学上是用弧度而非角度,因为360的容易整除对数学不重要,而数学使用弧度更方便。角度和弧度关系是:2π弧度=360°。从而1°≈0.0174533弧度,1弧度≈57.29578°。
1) 角度转换为弧度公式:弧度=角度÷180×π
2)弧度转换为角度公式: 角度=弧度×180÷π
常量与变量
常量其值不可改变,符号常量名通常用大写。
变量是以某标识符为名字,其值可以改变的量。标识符是以字母或下划线开头的一串由字母、数字或下划线构成的序列,请注意第一个字符必须为字母或下划线,否则为不合法的变量名。变量在编译时为其分配相应存储单元。

更多文章:
force-unicode-font是什么意思?ღ᭄ꦿ这些特殊字是怎么来的
2026年9月27日 23:50
java重载和覆盖的定义(java中方法重载和重写的区别和定义)
2026年9月27日 22:50
变幻金刚魔方教程图解(变幻金刚魔方的最后一步,研究了很长时间就是搞不 出来,能教教我吗)
2026年9月27日 21:00
怎样使用dreamweaver(怎么用dreamweaver制作网页如何用dreamweaver制作网页)
2026年9月27日 20:40
css提交按钮怎么写(html:submit能加css样式吗)
2026年9月27日 19:20
雨崩近年危险事件调查(下雨好长时间了,去雨崩的路况怎么样有刚从雨崩回来的吗)
2026年9月27日 13:20
shell脚本substr(SHELL脚本对LINUX下指定文本文件的满足条件的行的特定位置字符串进行替换)
2026年9月27日 10:50





