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

📄 unit1.pas

📁 极坐标与X-Y坐标相互转换工具
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
X,Y,Xo,Yo,Xn,Yn,dX,dY,R,T,dT,T0,Tn,pi:real;
begin
 pi:=3.14159265;
Xo:=strtofloat(Edit1.Text)-50;
Yo:=strtofloat(Edit2.Text)-50;
dX:=strtofloat(Edit3.Text)/1000;
dY:=strtofloat(Edit4.Text)/1000;
if Xo=0 then
 begin
 T0:=pi/2;
 T:=pi/2;
 end
else begin
  T0:=ArcTan(Yo/Xo);//2坐标系参考角
  T:=ArcTan(sqrt(Sqr(dX+Xo)+Sqr(Yo+dY)-Sqr(Xo))/Xo); //1坐标系参考角
  if (Xo<0) and (Yo>0) then
   begin
    T0:=pi+T0;
    T:=pi+T;
   end
  else if (Xo<0) and (Yo<0) then
   begin
    T0:=pi+T0;
    T:=pi-T;
   end
  else if (Xo>0) and (Yo<0) then
   begin
    //T0:=T0;
    T:=-T;
   end ;
 end;

R:= sqrt(Sqr(Xo+dX)+Sqr(Yo+dY));
//参考坐标值
Edit5.Text:=floattostr(0);
//Edit5.Text:=floattostr(cos(dT)*R-strtofloat(Edit1.Text));
Edit6.Text:=floattostr((sin(T)*R-Yo)*1000);

dT:=T0-T; //两座标系极角差 2-1
//第一点坐标
Xo:=strtofloat(Edit7.Text)-50;
Yo:=strtofloat(Edit8.Text)-50;
dX:=strtofloat(Edit9.Text)/1000;
dY:=strtofloat(Edit10.Text)/1000;

T:=ArcTan((Yo+dY)/(Xo+dX))-dT;
  if (Xo<0) and (Yo>0) then
   begin
    //T0:=pi+T0;
    T:=pi+T;
   end
  else if (Xo<0) and (Yo<0) then
   begin
    //T0:=pi+T0;
    T:=pi-T;
   end
  else if (Xo>0) and (Yo<0) then
   begin
    //T0:=T0;
    T:=-T;
   end ;

R:= sqrt(Sqr(Xo+dX)+Sqr(Yo+dY));
Edit11.Text:=floattostr((cos(T)*R-Xo)*1000);
Edit12.Text:=floattostr((sin(T)*R-Yo)*1000);
//Edit6.Text:=floattostr(dT);
end;

end.

⌨️ 快捷键说明

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