生成螺旋线形状的随机点
2016-06-12 12:26
337 查看
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #define PI 3.1415926535 void generate_spiral(); int size_of_point; //the total size of points int range; //the range of x and y of all points int initial_phase; //decide position of the first point int cycles; //the number of laps char filename[200]; int main(int argc, char* argv[]) { if( argc != 6 ) { printf("This program need 5 paremeter to specified by user" "\n\tthe first indicate the total size of point(eg. 100,300,500...)" "\n\tthe second indicate the range of x and y of all points(hits:10,20...)" "\n\tthe third indicate the initial_phase of spiral(hits:60,150,240...)" "\n\tthe forth indicate the number of cycles of spiral(hits:3,10,20...)" "\n\tthe last one indicate the output filename to save the value of point"); exit(0); } size_of_point = atoi(argv[1]); range = atoi(argv[2]); initial_phase = atoi(argv[3]); cycles = atoi(argv[4]); strcat(filename, argv[5]); generate_spiral(); return 0; } void generate_spiral() { FILE* fwrite; if( NULL == (fwrite = fopen(filename, "w"))) { printf("open file error"); exit(0); } int t; double s; double x; double y; double angle; for( t = 1; t <= size_of_point; t++ ) { s = range * t/(double)size_of_point; angle = initial_phase + t/(double)size_of_point * 360 * cycles; x = s * cos(angle * PI / 180); y = s * sin(angle * PI / 180); fprintf(fwrite, "%f\t%f\n", x, y); } fclose(fwrite); }
下图为使用改代码使用不同的参数形成的两条螺旋线
相关文章推荐
- 浅谈Java自动装箱与拆箱及其陷阱
- asp.net:webconfig简单数据库配置
- 解决eclipse字体太小问题
- MySQL之——提示"mysql deamon failed to start"错误的解决方法
- PAT天梯赛练习题——L3-005. 垃圾箱分布(暴力SPFA)
- SAP中采购订单状态与MRP的关系
- gulp教程之gulp中文API
- 政治哲学与幸福根基 (David Miller )
- 各种常用方法封装
- C++之虚函数
- C# 使用Parallel并行开发Parallel.For、Parallel.Foreach实例
- Ghost文件封装说明
- IOHelper(自制常用的输入输出的帮助类)
- android应用程序第4课:activity初步
- win2008 IP安全策略下配置一个IP段的写法
- 图片宽度为控件宽度,高度按比例缩放
- mac go sublime 3
- 2、$scope和$rootScope的作用域
- 装机自动化脚本介绍
- 初学 retrofit2与RXJava 的搭配使用