var Eps = 0.001;
function MCompl(X,Y)
{
var Z = {Re:0, Im:0}
if (Math.abs(X)<Eps*Eps*Eps) {X=0}
if (Math.abs(Y)<Eps*Eps*Eps) {Y=0}
Z.Re=X;
Z.Im=Y;
return Z;
} // MCompl
function CompNeg(X)
{
return MCompl(-X.Re,-X.Im);
} // CompNeg
function CompSum(X,Y)
{
var Z = {Re:undefined, Im:undefined} // инициализация структуры комплексного числа
Z.Re=X.Re+Y.Re;
Z.Im=X.Im+Y.Im;
return Z
} // CompSum
function CompSub(X,Y)
{
var Z = {Re:undefined, Im:undefined} // инициализация структуры комплексного числа
Z.Re=X.Re-Y.Re;
Z.Im=X.Im-Y.Im;
return Z
} // CompSub
function CompMul(X,Y)
{
var Z = {Re:undefined, Im:undefined} // инициализация структуры комплексного числа
Z.Re=X.Re*Y.Re-X.Im*Y.Im;
Z.Im=X.Re*Y.Im+Y.Re*X.Im;
return Z;
} // CompMul
function CompDiv(X,Y)
{
var Z = {Re:undefined, Im:undefined} // инициализация структуры комплексного числа
Success=true;
if (Math.abs(Y.Re*Y.Re+Y.Im*Y.Im)<Eps) {Success=false}
Z.Re=(X.Re*Y.Re+X.Im*Y.Im)/(Y.Re*Y.Re+Y.Im*Y.Im);
Z.Im=(Y.Re*X.Im-X.Re*Y.Im)/(Y.Re*Y.Re+Y.Im*Y.Im);
return Z;
} // CompDiv
function CompSqr(X)
{
return CompMul(X,X);
} // CompSqr
function CompSqrt(X)
{
var A,B;
V=Math.sqrt(X.Re*X.Re+X.Im*X.Im)+X.Re;
A=Math.sqrt(V/2);
V=Math.sqrt((Math.sqrt(X.Re*X.Re+X.Im*X.Im)-X.Re)/2);
if (X.Im>=0) {B=Math.sqrt((Math.sqrt(X.Re*X.Re
+X.Im*X.Im)-X.Re)/2)} else {B=-Math.sqrt((Math.sqrt(X.Re*X.Re
+X.Im*X.Im)-X.Re)/2)};
return MCompl(A,B);
} // CompSqrt
function Diskr(P1,P2,P3,P4,P5,P6,P7,P8,P9)
{
return P1*P5*P9+P4*P8*P3+P7*P2*P6-P7*P5*P3-P1*P8*P6-
P4*P2*P9;
} // Diskr
function DiskrComp(P1,P2,P3,P4,P5,P6,P7,P8,P9)
{
var S1 = {Re:0, Im:0}
var S2 = {Re:0, Im:0}
var S3 = {Re:0, Im:0}
var S4 = {Re:0, Im:0}
var S5 = {Re:0, Im:0}
var S6 = {Re:0, Im:0}
var D1 = {Re:0, Im:0}
var D2 = {Re:0, Im:0}
S1=CompMul(P1,CompMul(P5,P9));
S2=CompMul(P4,CompMul(P8,P3));
S3=CompMul(P7,CompMul(P2,P6));
S4=CompMul(P7,CompMul(P5,P3));
S5=CompMul(P1,CompMul(P8,P6));
S6=CompMul(P4,CompMul(P2,P9));
D1=CompSum(S1,CompSum(S2,S3));
D2=CompSum(S4,CompSum(S5,S6));
return CompSub(D1,D2);
} // DiskrComp
function SC(X1,Y1,X2,Y2)
{
var Dx,Dy,SCDP;
var SCDP = {S:0, C:0, D:0, P:false}
SCDP.P=false;
Dx=X2-X1; Dy=Y2-Y1; SCDP.D=Math.sqrt(Dx*Dx+Dy*Dy);
if (SCDP.D>0)
{
SCDP.S=Dy/SCDP.D;
SCDP.C=Dx/SCDP.D;
SCDP.P=true;
}
return SCDP
} // SC
function ArcSin(X)
{
var A
if ((X>-1) && (X<1)) A=Math.atan(X/Math.sqrt(1-X*X));
if (X>1-Eps*Eps*Eps*Eps) A=Math.PI/2;
if (X<-1+Eps*Eps*Eps*Eps) A=-Math.PI/2;
return A;
} // ArcSin
function ArcCos(X)
{
return (Math.PI/2-ArcSin(X));
} // ArcCos
function Fi(Sa,Ca,Sb,Cb)
{
var Da1,Da2,Fi1,Fi2;
Fi2=ArcSin(Sb);
if ((Sa>=0) && (Ca>=0)) Fi1=ArcSin(Sa);
if ((Sa>=0) && (Ca<0)) Fi1=Math.PI-ArcSin(Sa);
if ((Sa<0) && (Ca>=0)) Fi1=ArcSin(Sa);
if ((Sa<0) && (Ca<0)) Fi1=-Math.PI-ArcSin(Sa);
if ((Sb>=0) && (Cb>=0)) Fi2=ArcSin(Sb);
if ((Sb>=0) && (Cb<0)) Fi2=Math.PI-ArcSin(Sb);
if ((Sb<0) && (Cb>=0)) Fi2=ArcSin(Sb);
if ((Sb<0) && (Cb<0)) Fi2=-Math.PI-ArcSin(Sb);
return Fi2-Fi1;
} // Fi
function LinLin(X1,Y1,X2,Y2,X3,Y3,X4,Y4)
{
var A1,B1,C1,A2,B2,C2,ZZ;
var P = {X:undefined, Y:undefined, W:undefined,P:false}
A1=Y1-Y2; B1=X2-X1;
A2=Y3-Y4; B2=X4-X3;
ZZ=A1*B2-B1*A2;
P.P=false;
if (Math.abs(ZZ)>1E-2)
{
C1=X1*Y2-Y1*X2;
C2=X3*Y4-Y3*X4;
P.X=(B1*C2-C1*B2)/ZZ;
P.Y=(C1*A2-A1*C2)/ZZ;
P.W=1;
P.P=true;
}
if ((Math.abs(ZZ)<=1E-2) || (Math.abs(P.X)>1000000000) || (Math.abs(P.Y)>1000000000))
{
P.X=B1;
P.Y=-A1;
P.W=0;
}
return P;
} // LinLin
function ProcA(X1,Y1,X2,Y2,Xt,Yt,V)
{
var S,C,Dl,Dx,Xt1,Yt1,Df,X3,Y3,X4,Y4,A,B;
var XTD = {Xt:undefined, Yt:undefined, D:undefined, B:undefined}
XTD.B=false;
SCDP=SC(X1,Y1,X2,Y2);
Df=Fi(0,1,SCDP.S,SCDP.C);
Dx=90*Math.PI/180+Df;
X3=Xt+200*Math.cos(Dx);
Y3=Yt+200*Math.sin(Dx);
X4=Xt-200*Math.cos(Dx);
Y4=Yt-200*Math.sin(Dx);
P=LinLin(X1,Y1,X2,Y2,X3,Y3,X4,Y4);
A=(Xt-Xt1)*(Xt-P.X);
B=(Yt-Yt1)*(Yt-P.Y);
XTD.D=Math.sqrt(A+B);
if (XTD.D<V)
{
XTD.Xt=P.X;
XTD.Yt=P.Y;
XTD.B=true;
}
return XTD;
} // ProcA
function LinLinComp(X1,Y1,X2,Y2,X3,Y3,X4,Y4)
{
var A1,B1,C1,A2,B2,C2;
var B,BB,BBB,Prizn;
var V,XD;
var R={XX:0,YY:0,ZZ:0,B:undefined}
Prizn=false;
if ((X1.Im==0) && (X2.Im==0) && (X3.Im==0) && (X4.Im==0) && (Y1.Im==0) && (Y2.Im==0) && (Y3.Im==0) && (Y4.Im==0))
{
V=0.0001;
BB=ProcA(X1.Re,Y1.Re,X2.Re,Y2.Re,X3.Re,Y3.Re,V);
BBB=ProcA(X1.Re,Y1.Re,X2.Re,Y2.Re,X4.Re,Y4.Re,V);
if (BB.B && BBB.B)
{
B1=CompSub(X2,X1);
A1=CompSub(Y1,Y2);
XX=B1;
YY=CompSub(MCompl(0,0),A1);
ZZ=MCompl(0,0);
R.XX=XX;
R.YY=YY;
R.ZZ=ZZ;
R.B=Prizn;
return R;
}
}
A1=CompSub(Y1,Y2); B1=CompSub(X2,X1);
A2=CompSub(Y3,Y4); B2=CompSub(X4,X3);
ZZ=CompSub(CompMul(A1,B2),CompSub(B1,A2));
if ((Math.abs(ZZ.Re)>1E-25) || (Math.abs(ZZ.Im)>1E-25))
{
C1=CompSub(CompMul(X1,Y2),CompMul(Y1,X2));
C2=CompSub(CompMul(X3,Y4),CompMul(Y3,X4));
Prizn=true
XX=CompDiv(CompSub(CompMul(B1,C2),CompMul (C1,B2)),ZZ);
if (Success==false) Prizn=false;
YY=CompDiv(CompSub(CompMul(C1,A2),CompMul (A1,C2)),ZZ);
if (Success==false) Prizn=false;
ZZ=MCompl(1,0);
}
if ((Math.abs(ZZ.Re)<=1E-25) || (Math.abs(XX.Re)>1000000000) || (Math.abs(YY.Re)>1000000000))
{
XX=B1;
YY=CompSub(MCompl(0,0),A1);
ZZ=MCompl(0,0);
}
R.XX=XX;
R.YY=YY;
R.ZZ=ZZ;
R.B=Prizn;
return R;
} // LinLinComp
function ComDuga1(Xc1,Yc1,Xc2,Yc2,R1,R2)
{
var DeltaX,DeltaY,DeltaX_2,DeltaY_2,R1_2,R2_2,Xc1_2,Xc2_2,Yc1_2,Yc2_2,U,V,V
1,V2,V3,A,B,C,D,P,Q;
var S;
var P= {X1:undefined,Y1:undefined,X2:undefined,Y2:undefined}
DeltaX=CompSub(Xc2,Xc1);
DeltaY=CompSub(Yc2,Yc1);
R1_2=CompMul(R1,R1);
R2_2=CompMul(R2,R2);
Xc1_2=CompMul(Xc1,Xc1);
Xc2_2=CompMul(Xc2,Xc2);
Yc1_2=CompMul(Yc1,Yc1);
Yc2_2=CompMul(Yc2,Yc2);
U=CompSub(R1_2,R2_2);
U=CompSub(U,Yc1_2);
U=CompSum(U,Yc2_2);
U=CompSub(U,Xc1_2);
U=CompSum(U,Xc2_2);
DeltaX_2=CompMul(DeltaX,DeltaX);
DeltaY_2=CompMul(DeltaY,DeltaY);
if ((Math.abs(Xc1.Re-Xc2.Re)>Eps) || (Math.abs(Xc1.Im-
Xc2.Im)>Eps))
{
V=CompDiv(DeltaY_2,DeltaX_2,V);
A=CompSum(V,MCompl(1,0));
V1=CompDiv(CompMul(MCompl(2,0),DeltaY),DeltaX);
V1=CompMul(V1,Xc1);
V2=CompDiv(CompMul(U,DeltaY),DeltaX_2);
V3=CompMul(MCompl(2,0),Yc1);
B=CompSub(V1,V2);
B=CompSub(B,V3);
V1=CompDiv(CompMul(U,U),CompMul(MCompl (4,0),DeltaX_2));
V2=CompDiv(U,DeltaX);
C=CompSub(V1,CompMul(V2,Xc1));
C=CompSum(C,Xc1_2);
C=CompSum(C,Yc1_2);
C=CompSub(C,R1_2);
D=CompSub(CompMul(B,B),CompMul(MCompl (4,0),CompMul(A,C)));
Y1=CompDiv(CompSum(CompNeg(B),CompSqrt (D)),CompMul(MCompl(2,0),A));
Y2=CompDiv(CompSub(CompNeg(B),CompSqrt (D)),CompMul(MCompl(2,0),A));
V1=CompSub(U,CompMul(MCompl(2,0),CompMul (Y1,DeltaY)));
X1=CompDiv(V1,CompMul(MCompl(2,0),DeltaX));
V1=CompSub(U,CompMul(MCompl(2,0),CompMul (Y2,DeltaY)));
X2=CompDiv(V1,CompMul(MCompl(2,0),DeltaX));
P=CompDiv(DeltaY_2,DeltaX_2,P);
P=CompSum(P,MCompl(1,0));
Q=CompMul(A,A);
Q=CompDiv(D,Q);
P=CompMul(Q,P);
P=CompSqrt(P);
P=CompDiv(P,MCompl(2,0));
} else
if ((Math.abs(Yc1.Re-Yc2.Re)>Eps) || (Math.abs(Yc1.Im-
Yc2.Im)>Eps))
{
V=CompDiv(DeltaX_2,DeltaY_2);
A=CompSum(V,MCompl(1,0));
V1=CompDiv(CompMul(MCompl(2,0),DeltaX),DeltaY);
V1=CompMul(V1,Yc1);
V2=CompDiv(CompMul(U,DeltaX),DeltaY_2);
V3=CompMul(MCompl(2,0),Xc1);
B=CompSub(V1,V2);
B=CompSub(B,V3);
V1=CompDiv(CompMul(U,U),CompMul(MCompl (4,0),DeltaY_2));
V2=CompDiv(U,DeltaY);
C=CompSub(V1,CompMul(V2,Yc1));
C=CompSum(C,Yc1_2);
C=CompSum(C,Xc1_2);
C=CompSub(C,R1_2);
D=CompSub(CompMul(B,B),CompMul(MCompl (4,0),CompMul(A,C)));
X1=CompDiv(CompSum(CompNeg(B),CompSqrt (D)),CompMul(MCompl(2,0),A));
X2=CompDiv(CompSub(CompNeg(B),CompSqrt (D)),CompMul(MCompl(2,0),A));
V1=CompSub(U,CompMul(MCompl(2,0),CompMul (X1,DeltaX)));
Y1=CompDiv(V1,CompMul(MCompl(2,0),DeltaY));
V1=CompSub(U,CompMul(MCompl(2,0),CompMul (X2,DeltaX)));
Y2=CompDiv(V1,CompMul(MCompl(2,0),DeltaY));
}
P.X1=X1;
P.Y1=Y1;
P.X2=X2;
P.Y2=Y2;
return P;
} // ComDuga1
Транслятор программы, представленной на языке системы Симплекс, в код на языке JavaScript.