⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 两点间距离和坐标方位角计算程序。可计算两点间距离和两点方向的方位角。
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
 #define PI 3.141592655
 #include "Unit1.h"
 #include "stdio.h"
 #include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
FILE *stream,*fp1;
DHHD(d)
double *d;
{
 double d1,d2,i1,i2;
  *d=*d+1.0E-12;
  i1=floor(*d);
  d1=(*d-i1)*100.0;
  i2=floor(d1);
  d2=(*d-i1-i2/100.0)*10000.0;
  *d=i1+i2/60.0+d2/3600.0;
  *d=*d*PI/180.0;
  return *d;
  }

HDHD(double *d)
{
 double d1,d2,i1,i2;
 *d=*d*180.0/PI;
 i1=floor(*d);
 d1=(*d-i1)*60;
 i2=floor(d1);
 d2=(d1-i2)*60;
 *d=i1+i2/100.0+d2/10000.0;
 return *d;
 }


//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
try
{

char outfilename[60],DH[1000][10],XH[10],line1[200];
double X[1000],Y[1000],EL[1000],A;
int i,j;
   StrCopy(outfilename,JGWJ->Text.c_str());
   fp1=fopen(outfilename,"w");
   fclose(fp1);
   fp1=fopen(outfilename,"w");
   for (int I = 0; I < ListBox1->Items->Count; I ++)
    {
      stream = fopen(ListBox1->Items->Strings[I].c_str(), "r");
         for(i=0;!feof(stream);i++)
        {
        fscanf(stream,"%s%lf%lf%lf\n",DH[i],&X[i],&Y[i],&EL[i]);      /*读已知数据*/
       // fprintf(fp1,"%10s%10s %.3f 20%.3f %.3f %.3f %.3f\n",XH,DH,X,Y,EL,EH,EL-0.029);
        }
        j=i;
        rewind(stream);

 //       fgets(line1,170,stream);
       for(i=1;i<j;i++)
        {
    A=atan((Y[i]-Y[i-1])/(X[i]-X[i-1]));
    A=fabs(A);
    if((Y[i]-Y[i-1])>=0&&(X[i]-X[i-1])<0)A=A+0;
    if((Y[i]-Y[i-1])>=0&&(X[i]-X[i-1])<0)A=180*PI/180-A;
    if((Y[i]-Y[i-1])<=0&&(X[i]-X[i-1])>0)A=360*PI/180-A;
    if((Y[i]-Y[i-1])<=0&&(X[i]-X[i-1])<0)A=A+180*PI/180;
    HDHD(&A);
      //  fscanf(stream,"%s%lf%lf%lf\n",DH,&X[i],&Y[i],&EL[i]);      /*读已知数据*/
       fprintf(fp1,"%10s  %.3f  %.3f \n",DH[i-1],X[i-1],Y[i-1]);
       fprintf(fp1,"%45.4f\n",A);
        }
      fprintf(fp1,"%10s  %.3f  %.3f \n",DH[j-1],X[j-1],Y[j-1]);
      fclose(stream);
     }

    fclose(fp1);
     Application->MessageBox("计算数据结束。","提示",MB_OK);
 }
 catch(...)
 {
 Application->MessageBox("错误。","提示",MB_OK);
 Close();
 }                
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 OpenDialog1->Filter="Txt Files(*.txt)|*.txt|All Files(*.*)|*.*";
OpenDialog1->Execute();
  ListBox1->Items->Clear();
     for (int I = 0; I < OpenDialog1->Files->Count; I ++)
    {
        // read the first line from the file
        ListBox1->Items->Append(OpenDialog1->Files->Strings[I].c_str());
    }

             
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
SaveDialog1->Filter="Dat Files(*.dat)|*.dat|All Files(*.*)|*.*";
SaveDialog1->Execute();
JGWJ->Text=SaveDialog1->FileName;            
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -