?? 閉合導線計算程序.cpp
字號:
#include<iostream.h>
#include<math.h>
#define PI 3.14159265358
double disp360( double j)
{ //用度制表示弧度
double d;
d=j*180.0/PI;
return d;
}
double fm_d( double x)
{
int t(0);
double x4;
double x3,x5;
if(x<0)
{t=2;
x=-x;
}
double x1=floor(x*100.0);
double x2=x*100.0-x1;
x3=x2/36.0;
x4=floor((x*100.0-x2)/100.0);
x5=(x*100-x2)/100.0-x4;
x5=x5*10.0/6.0;
//
if(t==0) return(floor(x)+x3+x5);
else return-(floor(x)+x3+x5);
}
double d_fm( double x)
{ //用度分秒表示dou
double x4;
double x3,x5;
int b(0);
if(x<0.0){x=-x;b=2;}
double x1=floor(x);
double x2=x-x1;
x3=floor(60.0*x2);//this is the fen value
x4=(x2*60.0-x3)*60.0;//this is the miao value
x5=x4-60.0;if(x5<0.0) x5=-x5;
if(x5<0.0000000001){
x4-=60.0;
x3+=1;
}
x5=x3-60.0;if(x5<0) x5=-x5;
if(x5<0.0000000001){
x3-=60.0;
x1+=1.0;
}
if(b==0) return x1+x3/100.0+x4/10000.0;
else return -(x1+x3/100.0+x4/10000.0);
}
double h_d( double x)
{
double y=disp360(x);
ss: if(y>=360.0) {
y-=360.0;
goto ss;
}
return d_fm(y);
}
double d_h( double x)
{
double y=fm_d(x);
return y*PI/180.0;
}
void main()
{
int n;//define the number of angle;
cout<<" Please input the number of angle......"<<endl;
cin>>n;
double a[50][50],fx0(0),fy0(0),fx(0),fy(0),fs(0),s0(0);
double ang[80],s[80],ang0(0),x[80],y[80],dx[80],dy[80];
cout<<"please input the start coordernates:"<<endl;
cout<<"x=";
cin>>x[1];
cout<<endl<<"y=";
cin>>y[1];
cout<<"please input the start direction:";
cin>>a[0][1];a[0][1]=d_h(a[0][1]);
cout<<endl<<" Please input the s and angle of angles......"<<endl;
for(int i=1;i<=n;i++)
{
cout<<endl<<"s("<<i<<")=";
cin>>s[i];s0+=s[i];
cout<<endl<<"ang("<<i<<")=";
cin>>ang[i];ang[i]=d_h(ang[i]);ang0+=ang[i];
cout<<endl;
}
cout<<"導線角度閉合差為:"<<h_d((n-2)*PI-ang0)<<endl;
ang0=((n-2)*PI-ang0)/n;
for(i=1;i<=n;i++)//ok direction calculation;
{
a[i][i+1]=a[i-1][i]+PI+ang[i]+ang0;
if(i==1) a[i][i+1]=a[i-1][i]+ang[i]+ang0;
ee: if(a[i][i+1]-2*PI>0) {a[i][i+1]-=2*PI;goto ee;}
cout<<"direction of "<<i<<"to"<<i+1<<"="<<h_d(a[i][i+1])<<endl;
if(i!=n)
{
dx[i]=s[i]*cos(a[i][i+1]);fx+=dx[i];x[i+1]=x[i]+dx[i];cout<<"x("<<i+1<<")'="<<x[i+1]<<endl;
dy[i]=s[i]*sin(a[i][i+1]);fy+=dy[i];y[i+1]=y[i]+dy[i];cout<<"y("<<i+1<<")'="<<y[i+1]<<endl;
}
else
{
dx[i]=s[i]*cos(a[i][i+1]);fx+=dx[i];x[0]=x[i+1]=x[i]+dx[i];cout<<"x("<<1<<")'="<<x[i+1]<<endl;
dy[i]=s[i]*sin(a[i][i+1]);fy+=dy[i];y[0]=y[i+1]=y[i]+dy[i];cout<<"y("<<1<<")'="<<y[i+1]<<endl;
}
}
cout<<" fx="<<fx<<endl;cout<<" fy="<<fy<<endl;
fs=sqrt(fx*fx+fy*fy);cout<<" fs="<<fs<<endl;
cout<<"s0="<<s0<<endl;
cout<<" 1/K="<<1<<"/"<<s0/fs<<endl;
for(i=1;i<=n;i++)
{
if(i!=n)
{
dx[i]=s[i]*cos(a[i][i+1])-fx*s[i]/s0;x[i+1]=x[i]+dx[i];cout<<"x("<<i+1<<")="<<x[i+1]<<endl;
dy[i]=s[i]*sin(a[i][i+1])-fy*s[i]/s0;y[i+1]=y[i]+dy[i];cout<<"y("<<i+1<<")="<<y[i+1]<<endl;
}
else
{
dx[i]=s[i]*cos(a[i][i+1]);x[i+1]=x[i]+dx[i]-fx*s[i]/s0;cout<<"x("<<1<<")="<<x[i+1]<<endl;
dy[i]=s[i]*sin(a[i][i+1]);y[i+1]=y[i]+dy[i]-fy*s[i]/s0;cout<<"y("<<1<<")="<<y[i+1]<<endl;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -