// Lets find the X,Y of H.
var Xh;
var Yh;
// Original Math:- D1 = sqrt((Xa - Xb)^2 + (Ya - Yb)^2)
var tmpXpow1 = (Xa-Xb);
var tmpXpow2 = Math.
Pow(tmpXpow1,
2);
var tmpYpow1 = (Ya-Yb);
var tmpYpow2 = Math.
Pow(tmpYpow1,
2);
var tmpD1 = tmpXpow2+ tmpYpow2;
var D1 = Math.
Sqrt(tmpD1
);
// Original Math:- (Xm , Ym) = ((Xa + Xb) / 2 , (Ya + Yb) / 2)
var Xm = (Xa + Xb) / 2;
var Ym = (Ya + Yb) / 2;
// Original Math:- g1 = (Ya - Yb) / (Xa - Xb)
var g1 = (Ya - Yb) / (Xa - Xb);
// Original Math:- g2 = -1 / g1
var g2 = -1 / g1;
// Original Math:- phi = atan(g2)
// Original Math:- D2 = D1 * tan(K) / 2
var D2 = D1 * tanK / 2;
// Original Math:- (Xh , Yh) = (Xm + D2 * cos(phi), Ym + D2 * sin(phi))
var cosPHI = Math.
Cos(phi
);
Xh = Xm + D2 * cosPHI;
var sinPHI = Math.
Sin(phi
);
Yh = Ym + D2 * sinPHI;
function ArcData(Xa, Ya, Xb, Yb, Xh, Yh)
{
/*Original Math Xc = [(Ya - Yh)(Xb^2 + Yb^2) + (Yh - Yb)(Xa^2 + Ya^2) + (Yb - Ya)(Xh^2 + Yh^2)]
-------------------------------------------------------------------------------
2*[Xb*Ya + Xa*Yh + Xh*Yb - Yb*Xa - Ya*Xh - Yh*Xb] */
var XbP = Math.
Pow(Xb,
2);
var YbP = Math.
Pow(Yb,
2);
var XaP = Math.
Pow(Xa,
2);
var YaP = Math.
Pow(Ya,
2);
var XhP = Math.
Pow(Xh,
2);
var YhP = Math.
Pow(Yh,
2);
var Xc = ((Ya-Yh)*(XbP+YbP)+(Yh - Yb)*(XaP+YaP)+(Yb-Ya)*(XhP + YhP)) / 2*(Xb*Ya + Xa*Yh + Xh*Yb - Yb*Xa - Ya*Xh - Yh*Xb);
//Yc = [(Xa - Xh)(Yb^2 + Xb^2) + (Xh - Xb)(Ya^2 + Xa^2) + (Xb - Xa)(Yh^2 + Xh^2)]
var Yc = ((Xa-Xh)*(YbP+XbP)+(Xh - Xb)*(YaP+XaP)+(Xb-Xa)*(YhP + XhP)) / 2*(Yb*Xa + Ya*Xh + Yh*Xb - Xb*Ya - Xa*Yh - Xh*Yb);
// Original Math:- r = sqrt((Xa - Xc)^2 + (Ya - Yc)^2)
var r1 = (Xa-Xc);
var r2 = (Ya-Yc);
var R = Math.
Pow((r3+r4
),
2);
/*Start angle = angle between horizontal and the line joining C and A = atan2(Ya - Yc, Xa - Xc)
Finish angle = angle between horizontal and the line joining C and B = atan2(Yb - Yc, Xb - Xc) */
var Sag1 = Ya - Yc;
var Sag2 = Xa - Xc;
var Eag1 = Yb - Yc;
var Eag2 = Xb - Xc;
var Sag = Math.
Atan2(Sag1,Sag2
);
var Eag = Math.
Atan2(Eag1,Eag2
);
/*4) any angle between the start angle and finish angle will give you a point along the arc, so you can use code like the following pseudo code to generate these points:
for each angle theta between the start angle and finish angle do the following
calculate the x coordinate as Xp = Xc + r * cos(theta)
calculate the y coordinate as Yp = Yc + r * sin(theta)
output the point on the arc as (Xp,Yp) */
var CosAG = Math.
Cos(Sag
);
var SinAG = Math.
Sin(Sag
);
var Xp1 = Xc + R * CosAG;
var Yp1 = Yc + R * SinAG;
var CosAG1 = Math.
Sin(Eag
);
var SinAG1 = Math.
Sin(Eag
);
var Xp2 = Xc + R * CosAG1;
var Yp2 = Yc + R * SinAG1;