点位测设生成随机数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | //此程序为点位测设随机生成训练使用坐标而设计 //2019.6.2 //设计人:YHJ //商业使用需授权,最终解释权归设计者本人所有 #include<iostream> #include<math.h> #include<unistd.h> using namespace std; int main() { cout<< "程序说明:使用前提条件需要获取AB线段的准确距离,P点的角度范围,direction='L'(-90~0)/'R'(0~90)/'0'(手动输入角度范围,[-90~90])" <<endl; float R( float x0, float y0, float x, float y, float angle, int num); //声明随机生成范围P点坐标函数 float xa, ya, xb, yb, ab=29.740; int left_angle = -90, right_angle = 90; cout<<endl<< "input distance of AB" <<endl; cout<< ">>AB = " ; //ab已知点距离 cin>>ab; char direction= 'L' ; cout<< "input direction" <<endl<< ">>(L/R/0):" ; //点P坐标的随机范围,'L'=-90~0,'R'=0~90,'0'为手动输入左右范围 cin>>direction; if (direction== '0' ) { cout<< "input range of angle:" <<endl << ">>left angle=" ; cin>>left_angle; cout<< ">>right angle=" ; cin>>right_angle; } else if (direction== 'L' || direction== 'l' ) { right_angle=0; } else if (direction== 'R' || direction== 'r' ) { left_angle=0; } else { cout<< "Input Error!" <<endl; return 0; } //随机生成A,B坐标 srand ( time (NULL)) ; xa= rand ()%1000000*0.001+300.0; sleep(1); srand ( time (NULL)) ; ya= rand ()%1000000*0.001; cout<< "A( " <<xa<< " , " <<ya<< " )" <<endl; sleep(1); srand ( time (NULL)) ; int t= rand ()%4+1; //随机象限 //cout<<t<<endl; if (t==1) { xb= rand ()%( int )(ab*1000)*0.001+xa; yb=ya+ sqrt ( pow (ab, 2)- pow ((xa-xb), 2)); } if (t==2) { xb=- rand ()%( int )(ab*1000)*0.001+xa; yb=ya+ sqrt ( pow (ab, 2)- pow ((xa-xb), 2)); } if (t==3) { xb=- rand ()%( int )(ab*1000)*0.001+xa; yb=ya- sqrt ( pow (ab, 2)- pow ((xa-xb), 2)); } if (t==4) { xb= rand ()%( int )(ab*1000)*0.001+xa; yb=ya- sqrt ( pow (ab, 2)- pow ((xa-xb), 2)); } cout<< "B( " <<xb<< " , " <<yb<< " )" <<endl; //随机生成P点坐标 for ( int i=0;i<3;i++) { sleep(1); srand ( time (NULL)) ; float distance= rand ()%10000*0.001+10; sleep(1); srand ( time (NULL)) ; float angle=( rand ()%(right_angle*100-left_angle*100)+(left_angle*100))*0.01; cout<<angle<<endl; float dx=xb-xa; float dy=yb-ya; float x_rand=distance*dx/ab+xa; float y_rand=distance*dy/ab+ya; //cout<<distance<<endl<<angle<<endl; R(xa,ya,x_rand,y_rand,angle,i); } cout<< ">>>" <<endl; return 0; } float R( float x0, float y0, float x, float y, float angle, int num) //随机生成P点坐标函数 { float dx=x-x0; float dy=y-y0; float x_=dx* cos (angle/180*3.14)-dy* sin (angle/180*3.14)+x0; float y_=dx* sin (angle/180*3.14)+dy* cos (angle/180*3.14)+y0; cout<< "P" <<num+1<< "( " <<x_<< " , " <<y_<< " )" <<endl; return 0; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)