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

📄 unit1.cpp

📁 直接解压即可
💻 CPP
字号:
//---------------------------------------------------------------------------

# include<math.h>
#include <vcl.h>
#pragma hdrstop
 #include<stdio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

 int xs1,ys1,xe1,ye1,xs2,ys2,xe2,ye2;
 int xc,yc;
   int R;

void __fastcall TForm1::Button1Click(TObject *Sender)
{ FILE *shuc;
shuc=fopen("d:\\shuch.scr","w");
 float A,B,C,t,z1,z2;
    float a;
    float zheng;
    float xe=xe1,ye=ye1;
      FILE *open;
       open=fopen("d:/line.txt","r");
       fscanf(open,"%d,%d",&xs1,&ys1);
       fscanf(open,"%d,%d",&xe1,&ye1);
       fscanf(open,"%d,%d",&xs2,&ys2);
       fscanf(open,"%d,%d",&xe2,&ye2);

  // xs1=StrToInt(Edit1->Text);
   //ys1=StrToInt(Edit2->Text);
  // xe1=StrToInt(Edit3->Text);
  // ye1=StrToInt(Edit4->Text);
  // xs2=StrToInt(Edit5->Text);
  // ys2=StrToInt(Edit6->Text);
  // xe2=StrToInt(Edit7->Text);
  // ye2=StrToInt(Edit8->Text);

   R=StrToInt(Edit9->Text);



     A=sqrt((xe1-xs1)*(xe1-xs1)+(ye1-ys1)*(ye1-ys1));  //求三条边长
     B=sqrt((xe2-xs2)*(xe2-xs2)+(ye2-ys2)*(ye2-ys2));
     C=sqrt((xs2-xs1)*(xs2-xs1)+(ys2-ys1)*(ys2-ys1));
     a=(acos((A*A+B*B-C*C)*1.0/(2*A*B)))*180/3.14159/2;   //求角度

    // cz=(A*A+B*B-C*C)*1.0/(2*A*B);
     //Canvas->TextOut(10,10,A);
    // Canvas->TextOut(10,40,B);
    // Canvas->TextOut(10,80,C);
     //Canvas->TextOut(10,110,cz);
  //   Canvas->TextOut(10,140,a);


      t=R/tan(a);
      zheng=t*(xs1-xe1)/A+xe1;
       if(zheng>=0)xe1=zheng+0.5;
       else xe1=zheng-0.5;
      zheng=t*(ys1-ye1)/A+ye1;
        if(zheng>=0)ye1=zheng+0.5;
        else ye1=zheng-0.5;
  //   Canvas->TextOut(10,10,xe1);
  //   Canvas->TextOut(150,10,ye1);

       zheng=t*(xs2-xe2)/B+xe2;
        if(zheng>=0)xe2=zheng+0.5;
        else xe2=zheng-0.5;
       zheng=t*(ys2-ye2)/B+ye2;
         if(zheng>=0)ye2=zheng+0.5;
         else ye2=zheng-0.5;

     //  Canvas->TextOut(10,50,xe2);
   //    Canvas->TextOut(150,50,ye2);

       z2=R/sin(a);
       z1=t*cos(a);
       zheng=z2*((xe1+xe2)/2-xe)/z1+xe;
         if(zheng>=0)xc=zheng+0.5;
         else xc=zheng-0.5;
       zheng=z2*((ye1+ye2)/2-ye)/z1+ye;
         if(zheng>=0)yc=zheng+0.5;
         else yc=zheng-0.5;

    //   Canvas->TextOut(10,30,xc);
    //   Canvas->TextOut(150,30,yc);


   fprintf(shuc,"%d,%d\n",xs1,ys1);  //保存分段后的各点坐标
   fprintf(shuc,"%d,%d\n",xe1,ye1);
   fprintf(shuc,"%d,%d\n",xc,yc);
   fprintf(shuc,"%d,%d\n",xs2,ys2);
   fprintf(shuc,"%d,%d\n",xe2,ye2);
    fclose(shuc);

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

void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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