?? unit1.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); //保存分段后的各點坐標(biāo)
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();
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -