📄 needle.cpp
字号:
// Needle.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
int main(int argc, char* argv[])
{
int radius, num, x, y, i, adjust;
double pi = 3.1415926535, step, angle = 0;
double result;
if(argc != 3)
{
printf("Usage: Needle.exe needle_len, dot_number\n\
\r\tUsed to generate coordinate positions on a circle.\n\
\r\tneedle_len: length of needle. i.e., length of the radius.\
\r\tdot_number: dot number on the circle boundary,\n\r\
\r\t e.g., if used for drawing a clock, it should be 60,\n\r\
\r\t if used for drawing a pie-chart, it should be 360.\n\r\
\r\te.g., Needle 20, 60\n\n\r" );
return 0;
}
radius = atoi(argv[1]);
num = atoi(argv[2]);
step = 2*pi/num;
for(i = 0; i < num; i++)
{
if(!(i%4))
{
printf("\n");
}
result = radius * sin(angle);
adjust = ((result - (int)result) >= 0.5)?1:0;
x = abs( (int)result + adjust );
result = radius * cos(angle);
adjust = ((result - (int)result) >= 0.5)?1:0;
y = abs( (int)result + adjust );
printf("{%-2d, %-2d}, ", x, y);
angle += step;
}
printf("\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -