|
function CalcP6(X,Y)
{
var Xb,Yb,Xe,Ye,T1,T2;
var Aa,Bb,Cx,Xc1,Yc1,R1,A,B,C,D;
var Temp1,Temp2;
var P= {X1:undefined,Y1:undefined,X2:undefined,Y2:undefined}
var X1= {X:undefined,Y:undefined}
var Y1= {X:undefined,Y:undefined}
var X2= {X:undefined,Y:undefined}
var Y2= {X:undefined,Y:undefined}
Prizn=false;
Xc1=Y.Xc;
Yc1=Y.Yc;
R1=Y.R;
if (X.Dir==znPlus)
{
X1=X.X1;
Y1=X.Y1;
X2=X.X2;
Y2=X.Y2;
}
else
{
X1=X.X2;
Y1=X.Y2;
X2=X.X1;
Y2=X.Y1;
}
Xb=X1.Re;
Yb=Y1.Re;
Xe=X2.Re;
Ye=Y2.Re;
Aa=CompSub(Y2,Y1);
Bb=CompSub(X2,X1);
Cc=CompSub(CompMul(X1,Y2),CompMul(Y1,X2));
if ((Math.abs(Aa.Re)<Eps) && (Math.abs(Bb.Re)<Eps) && (Math.abs(Aa.Im)<Eps) && (Math.abs(Bb.Im)<Eps))
{
Prizn=true;
return P;
}
if (Math.abs(Bb.Re)>=Eps)
{
A=CompSum(CompSqr(Bb),CompSqr(Aa));
B=CompMul((CompSum(CompSum(CompMul(Aa,Cc),CompMul(CompMul(Aa,Yc1),Bb)),CompMul(Xc1,CompSqr(Bb)))),MCompl(-2,0));
C=CompSub(CompSum(CompSum(CompSum(CompMul(CompSqr(Xc1),CompSqr(Bb)),CompSqr(Cc)),CompMul(MCompl(2,0),CompMul(Cc,CompMul(Yc1,Bb)))),
CompMul(CompSqr(Yc1),CompSqr(Bb))),CompMul(CompSqr(R1),CompSqr(Bb)));
D=CompSub(CompSqr(B),CompMul(MCompl(4,0),CompMul(A,C)));
if (Math.abs(D.Re)<Eps*Eps) D=MCompl(0,0);
X1=CompDiv(CompDiv(CompSum(CompSub(MCompl(0,0),B),CompSqrt(D)),MCompl(2,0)),A);
X2=CompDiv(CompDiv(CompSub(CompSub(MCompl(0,0),B),CompSqrt(D)),MCompl(2,0)),A);
Y1=CompDiv(CompSub(CompMul(CompSum(MCompl(0,0),Aa),X1),Cc),Bb);
Y2=CompDiv(CompSub(CompMul(CompSum(MCompl(0,0),Aa),X2),Cc),Bb);
if ((Math.abs(X.X1.Im)<Eps) && (Math.abs(X.Y1.Im)<Eps) && (Math.abs(X.X2.Im)<Eps) && (Math.abs(X.Y2.Im)<Eps))
{
A=MCompl((Xe-Xb)/Math.sqrt(Sqr(Xe-Xb)+Sqr(Ye-Yb)),0);
B=MCompl((Ye-Yb)/Math.sqrt(Sqr(Xe-Xb)+Sqr(Ye-Yb)),0);
if (Math.abs(A.Re)>Eps) T1=(X1.Re-Xb)/A.Re;
if (Math.abs(B.Re)>Eps) T1=(Y1.Re-Yb)/B.Re;
if (Math.abs(A.Re)>Eps) T2=(X2.Re-Xb)/A.Re;
if (Math.abs(B.Re)>Eps) T2=(Y2.Re-Yb)/B.Re;
if (T1>T2)
{
Temp1=X1; Temp2=Y1;
X1=X2;Y1=Y2;
X2=Temp1; Y2=Temp2;
}
}
if (R1.Re<0)
{
Temp1=X1; Temp2=Y1;
X1=X2;Y1=Y2;
X2=Temp1; Y2=Temp2;
}
P.X1=X1;
P.Y1=Y1;
P.X2=X2;
P.Y2=Y2;
return P;
}
else
{
Cc=CompSub(CompMul(Y1,X2),CompMul(X1,Y2));
A=CompSum(CompSqr(Bb),CompSqr(Aa));
B=CompMul((CompSum(CompSum(CompMul(Bb,Cc),CompMul(CompMul(Bb,Xc1),Aa)),CompMul(Yc1,CompSqr(Aa)))),MCompl(-2,0));
C=CompSub(CompSum(CompSum(CompSum(CompMul(CompSqr(Yc1),CompSqr(Aa)),CompSqr(Cc)),CompMul(MCompl(2,0),CompMul(Cc,CompMul(Xc1,Aa)))),
CompMul(CompSqr(Xc1),CompSqr(Aa))),CompMul(CompSqr(R1),CompSqr(Aa)));
D=CompSub(CompSqr(B),CompMul(MCompl(4,0),CompMul(A,C)));
if (Math.abs(D.Re)<Eps*Eps)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