//此程序为点位测设随机生成训练使用坐标而设计
//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;
}