【发布时间】:2015-12-22 14:50:00
【问题描述】:
我写了一个简单的代码来旋转一条线。以下是源代码:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
void main(){
int gd=DETECT, gm;
int x1, y1, x2, y2, t, deg, b1, b2;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Enter coordinates of line: ");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
printf("Enter angle of rotation: ");
scanf("%d",°);
line(x1, y1, x2, y2);
getch();
t = (22*deg)/(180*7);
b1 = cos(t)*x1 - sin(t)*y1;
b2 = cos(t)*x1 + sin(t)*y1;
line(x1,y1,b1,b2);
getch();
closegraph();
}
问题在于它会生成一些静态输出,并且不会根据给定的输入旋转线条。对于任何值 deg 变量,旋转线几乎相似。
【问题讨论】:
-
使用浮点数。如果你有一个不错的编译器,你会收到很多关于隐式整数到浮点转换的警告。你不应该通过非标准的、古老的垃圾编译器来学习 C 编程。