计算五星红旗上每颗小星各十个点纵横坐标的程序
来源:互联网 发布:怪医黑杰克ova 知乎 编辑:程序博客网 时间:2024/05/16 17:57
写完了国际象棋棋牌和中国象棋棋牌,我又想写一个五星红旗的绘制程序。对于五星红旗,每个五角星都有十个点。大星还好办,小星的角度都是不规则的。怎么样做到“两点确定一个五角星”?于是我编写了这个程序。四个星直接有差别,不能硬搬。
//**************************************** //程序功能:输入五角星中心点和某一个角的顶点// 坐标,输出其他各点坐标//编制人:刘聪//编制时间:2017年9月29日 //****************************************#include <iostream>#include <cmath>using namespace std;int main(){float pi = 3.141592653;int center[2] = {300,60};int point_1[2] = {274,75};int point_2[2] = {0};int point_3[2] = {0};int point_4[2] = {0};int point_5[2] = {0};int point_6[2] = {0};int point_7[2] = {0};int point_8[2] = {0};int point_9[2] = {0};int point_10[2] = {0};point_2[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_2[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_3[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 2 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_3[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 2 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_4[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 3 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_4[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 3 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 4 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 4 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 5 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 5 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 6 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 6 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 7 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 7 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 8 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 8 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 9 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 9 + atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));cout << endl << "point_2[0] = " << point_2[0];cout << '\t' << "point_2[1] = " << point_2[1] << endl;cout << endl << "point_3[0] = " << point_3[0];cout << '\t' << "point_3[1] = " << point_3[1] << endl;cout << endl << "point_4[0] = " << point_4[0];cout << '\t' << "point_4[1] = " << point_4[1] << endl;cout << endl << "point_5[0] = " << point_5[0];cout << '\t' << "point_5[1] = " << point_5[1] << endl;cout << endl << "point_6[0] = " << point_6[0];cout << '\t' << "point_6[1] = " << point_6[1] << endl;cout << endl << "point_7[0] = " << point_7[0];cout << '\t' << "point_7[1] = " << point_7[1] << endl;cout << endl << "point_8[0] = " << point_8[0];cout << '\t' << "point_8[1] = " << point_8[1] << endl;cout << endl << "point_9[0] = " << point_9[0];cout << '\t' << "point_9[1] = " << point_9[1] << endl;cout << endl << "point_10[0] = " << point_10[0];cout << '\t' << "point_10[1] = " << point_10[1] << endl;return 0;}
所求结果如下:(假定五星红旗宽为900,高为600)
第二个小星的center坐标为(360,120),point_1坐标为(330,124),代入程序计算得:
第三个小星的center坐标为(360,210),point_1坐标为(331,202),这时根据图样,两个角的加变成两个角的减,需要重写程序:
//**************************************** //程序功能:输入五角星中心点和某一个角的顶点// 坐标,输出其他各点坐标//编制人:刘聪//编制时间:2017年9月29日 //****************************************#include <iostream>#include <cmath>using namespace std;int main(){float pi = 3.141592653;int center[2] = {360,210};int point_1[2] = {331,202};int point_2[2] = {0};int point_3[2] = {0};int point_4[2] = {0};int point_5[2] = {0};int point_6[2] = {0};int point_7[2] = {0};int point_8[2] = {0};int point_9[2] = {0};int point_10[2] = {0};point_2[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_2[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_3[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 2 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_3[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 2 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_4[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 3 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_4[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 3 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 4 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 4 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 5 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 5 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 6 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 6 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 7 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 7 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 8 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 8 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 9 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 9 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));cout << endl << "point_2[0] = " << point_2[0];cout << '\t' << "point_2[1] = " << point_2[1] << endl;cout << endl << "point_3[0] = " << point_3[0];cout << '\t' << "point_3[1] = " << point_3[1] << endl;cout << endl << "point_4[0] = " << point_4[0];cout << '\t' << "point_4[1] = " << point_4[1] << endl;cout << endl << "point_5[0] = " << point_5[0];cout << '\t' << "point_5[1] = " << point_5[1] << endl;cout << endl << "point_6[0] = " << point_6[0];cout << '\t' << "point_6[1] = " << point_6[1] << endl;cout << endl << "point_7[0] = " << point_7[0];cout << '\t' << "point_7[1] = " << point_7[1] << endl;cout << endl << "point_8[0] = " << point_8[0];cout << '\t' << "point_8[1] = " << point_8[1] << endl;cout << endl << "point_9[0] = " << point_9[0];cout << '\t' << "point_9[1] = " << point_9[1] << endl;cout << endl << "point_10[0] = " << point_10[0];cout << '\t' << "point_10[1] = " << point_10[1] << endl;return 0;}计算结果为:
第四个小星的center坐标为(300,270),point_1坐标为(277,251),这时根据图样,point_2需要两个角相减,point_3需要36度减去之前point_2两个角的差,需要重写程序:
//**************************************** //程序功能:输入五角星中心点和某一个角的顶点// 坐标,输出其他各点坐标//编制人:刘聪//编制时间:2017年9月29日 //****************************************#include <iostream>#include <cmath>using namespace std;int main(){float pi = 3.141592653;int center[2] = {300,270};int point_1[2] = {277,251};int point_2[2] = {0};int point_3[2] = {0};int point_4[2] = {0};int point_5[2] = {0};int point_6[2] = {0};int point_7[2] = {0};int point_8[2] = {0};int point_9[2] = {0};int point_10[2] = {0};point_2[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos(atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])) - (float)36 / 360 * 2 * pi);point_2[1] = center[1] - (float)10 / cos((float)36 / 360 * 2 * pi) *sin(atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])) - (float)36 / 360 * 2 * pi);point_3[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi - (atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])) - (float)36 / 360 * 2 * pi));point_3[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi - (atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])) - (float)36 / 360 * 2 * pi));point_4[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 3 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_4[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 3 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 4 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_5[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 4 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 5 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_6[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 5 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 6 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_7[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 6 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 7 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_8[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 7 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[0] = center[0] - (float)30 *cos((float)36 / 360 * 2 * pi * 8 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_9[1] = center[1] + (float)30 *sin((float)36 / 360 * 2 * pi * 8 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[0] = center[0] - (float)10 / cos((float)36 / 360 * 2 * pi) *cos((float)36 / 360 * 2 * pi * 9 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));point_10[1] = center[1] + (float)10 / cos((float)36 / 360 * 2 * pi) *sin((float)36 / 360 * 2 * pi * 9 - atan((float)fabs(point_1[1] - center[1]) / (float)fabs(point_1[0] - center[0])));cout << endl << "point_2[0] = " << point_2[0];cout << '\t' << "point_2[1] = " << point_2[1] << endl;cout << endl << "point_3[0] = " << point_3[0];cout << '\t' << "point_3[1] = " << point_3[1] << endl;cout << endl << "point_4[0] = " << point_4[0];cout << '\t' << "point_4[1] = " << point_4[1] << endl;cout << endl << "point_5[0] = " << point_5[0];cout << '\t' << "point_5[1] = " << point_5[1] << endl;cout << endl << "point_6[0] = " << point_6[0];cout << '\t' << "point_6[1] = " << point_6[1] << endl;cout << endl << "point_7[0] = " << point_7[0];cout << '\t' << "point_7[1] = " << point_7[1] << endl;cout << endl << "point_8[0] = " << point_8[0];cout << '\t' << "point_8[1] = " << point_8[1] << endl;cout << endl << "point_9[0] = " << point_9[0];cout << '\t' << "point_9[1] = " << point_9[1] << endl;cout << endl << "point_10[0] = " << point_10[0];cout << '\t' << "point_10[1] = " << point_10[1] << endl;return 0;}
计算结果为:
阅读全文
0 0
- 计算五星红旗上每颗小星各十个点纵横坐标的程序
- 计算圆圈上点的坐标
- 计算地图上两坐标点之间的距离
- 528_计算圆弧上某一点的坐标
- 依据地图上的经纬度坐标计算某个点到多边形各边的距离
- 计算三点的坐标
- 不同3D坐标系上的点的坐标变换的计算
- 角度转弧度&根据弧度计算圆周上点的坐标的方法
- 如何计算地球球面上两个坐标点之间的弧度
- 计算两个坐标点之间的距离
- (非常好)计算匹配点的三维坐标
- 计算两个坐标点之间的距离
- 计算两个坐标点的距离
- 计算两平面坐标点的距离
- 根据角度计算圆的坐标点
- 用C#计算坐标点的镜像坐标
- 计算显示坐标旋转后点的坐标
- SQL函数之 计算地球上两个坐标点距离
- qt中delegate的使用
- 什么是图灵测试
- Android应用程序App应用上线流程
- OC中self.a和_a的访问的区别
- java实现 阿拉伯数字转换为汉字数字
- 计算五星红旗上每颗小星各十个点纵横坐标的程序
- 面试 linux常用命令
- SQL语句之计算次数出现最多的值
- MySQL配置主主复制和高可用
- android之深入了解setContentView
- 高通QXDM抓modem log
- 静态链表
- Java后台框架--Spring与远程方法调用
- 指定ie文档模式(解析页面的版本或ie版本)及几种指定方式的优先级