Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -17,52 +17,52 @@ Params:
|
|||
|
||||
Returns: The Circle that is tangent to c1, c2 and c3.
|
||||
*/
|
||||
pure nothrow Circle
|
||||
solveApollonius(in Circle c1, in Circle c2, in Circle c3,
|
||||
in Tangent t1, in Tangent t2, in Tangent t3) {
|
||||
alias immutable(double) imd;
|
||||
imd s1 = (t1 == Tangent.externally) ? 1.0 : -1.0;
|
||||
imd s2 = (t2 == Tangent.externally) ? 1.0 : -1.0;
|
||||
imd s3 = (t3 == Tangent.externally) ? 1.0 : -1.0;
|
||||
Circle solveApollonius(in Circle c1, in Circle c2, in Circle c3,
|
||||
in Tangent t1, in Tangent t2, in Tangent t3)
|
||||
pure nothrow @safe @nogc {
|
||||
alias Imd = immutable(double);
|
||||
Imd s1 = (t1 == Tangent.externally) ? 1.0 : -1.0;
|
||||
Imd s2 = (t2 == Tangent.externally) ? 1.0 : -1.0;
|
||||
Imd s3 = (t3 == Tangent.externally) ? 1.0 : -1.0;
|
||||
|
||||
imd v11 = 2 * c2.x - 2 * c1.x;
|
||||
imd v12 = 2 * c2.y - 2 * c1.y;
|
||||
imd v13 = c1.x ^^ 2 - c2.x ^^ 2 +
|
||||
Imd v11 = 2 * c2.x - 2 * c1.x;
|
||||
Imd v12 = 2 * c2.y - 2 * c1.y;
|
||||
Imd v13 = c1.x ^^ 2 - c2.x ^^ 2 +
|
||||
c1.y ^^ 2 - c2.y ^^ 2 -
|
||||
c1.r ^^ 2 + c2.r ^^ 2;
|
||||
imd v14 = 2 * s2 * c2.r - 2 * s1 * c1.r;
|
||||
Imd v14 = 2 * s2 * c2.r - 2 * s1 * c1.r;
|
||||
|
||||
imd v21 = 2 * c3.x - 2 * c2.x;
|
||||
imd v22 = 2 * c3.y - 2 * c2.y;
|
||||
imd v23 = c2.x ^^ 2 - c3.x ^^ 2 +
|
||||
Imd v21 = 2 * c3.x - 2 * c2.x;
|
||||
Imd v22 = 2 * c3.y - 2 * c2.y;
|
||||
Imd v23 = c2.x ^^ 2 - c3.x ^^ 2 +
|
||||
c2.y ^^ 2 - c3.y ^^ 2 -
|
||||
c2.r ^^ 2 + c3.r ^^ 2;
|
||||
imd v24 = 2 * s3 * c3.r - 2 * s2 * c2.r;
|
||||
Imd v24 = 2 * s3 * c3.r - 2 * s2 * c2.r;
|
||||
|
||||
imd w12 = v12 / v11;
|
||||
imd w13 = v13 / v11;
|
||||
imd w14 = v14 / v11;
|
||||
Imd w12 = v12 / v11;
|
||||
Imd w13 = v13 / v11;
|
||||
Imd w14 = v14 / v11;
|
||||
|
||||
imd w22 = v22 / v21 - w12;
|
||||
imd w23 = v23 / v21 - w13;
|
||||
imd w24 = v24 / v21 - w14;
|
||||
Imd w22 = v22 / v21 - w12;
|
||||
Imd w23 = v23 / v21 - w13;
|
||||
Imd w24 = v24 / v21 - w14;
|
||||
|
||||
imd P = -w23 / w22;
|
||||
imd Q = w24 / w22;
|
||||
imd M = -w12 * P - w13;
|
||||
imd N = w14 - w12 * Q;
|
||||
Imd P = -w23 / w22;
|
||||
Imd Q = w24 / w22;
|
||||
Imd M = -w12 * P - w13;
|
||||
Imd N = w14 - w12 * Q;
|
||||
|
||||
imd a = N * N + Q ^^ 2 - 1;
|
||||
imd b = 2 * M * N - 2 * N * c1.x +
|
||||
Imd a = N * N + Q ^^ 2 - 1;
|
||||
Imd b = 2 * M * N - 2 * N * c1.x +
|
||||
2 * P * Q - 2 * Q * c1.y +
|
||||
2 * s1 * c1.r;
|
||||
imd c = c1.x ^^ 2 + M ^^ 2 - 2 * M * c1.x +
|
||||
Imd c = c1.x ^^ 2 + M ^^ 2 - 2 * M * c1.x +
|
||||
P ^^ 2 + c1.y ^^ 2 - 2 * P * c1.y - c1.r ^^ 2;
|
||||
|
||||
// find a root of a quadratic equation.
|
||||
// This requires the circle centers not to be e.g. colinear
|
||||
imd D = b ^^ 2 - 4 * a * c;
|
||||
imd rs = (-b - sqrt(D)) / (2 * a);
|
||||
Imd D = b ^^ 2 - 4 * a * c;
|
||||
Imd rs = (-b - D.sqrt) / (2 * a);
|
||||
|
||||
return Circle(M + N * rs, P + Q * rs, rs);
|
||||
}
|
||||
|
|
@ -72,9 +72,9 @@ void main() {
|
|||
immutable c2 = Circle(4.0, 0.0, 1.0);
|
||||
immutable c3 = Circle(2.0, 4.0, 2.0);
|
||||
|
||||
alias Tangent.externally te;
|
||||
writeln(solveApollonius(c1, c2, c3, te, te, te));
|
||||
alias Te = Tangent.externally;
|
||||
solveApollonius(c1, c2, c3, Te, Te, Te).writeln;
|
||||
|
||||
alias Tangent.internally ti;
|
||||
writeln(solveApollonius(c1, c2, c3, ti, ti, ti));
|
||||
alias Ti = Tangent.internally;
|
||||
solveApollonius(c1, c2, c3, Ti, Ti, Ti).writeln;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
/*REXX program to solve the problem of Apollonius, named after the */
|
||||
/* Greek, Apollonius of Perga [Pergaeus] (circa 262 BC ──► 190 BC).*/
|
||||
w=20; numeric digits w-5 /*width used to display numbers. */
|
||||
c1.x=0; c1.y=0; c1.r=1
|
||||
c2.x=4; c2.y=0; c2.r=1
|
||||
c3.x=2; c3.y=4; c3.r=2
|
||||
call tell 'external tangent:', solveApollonius( 1, 1, 1)
|
||||
call tell 'internal tangent:', solveApollonius(-1,-1,-1)
|
||||
/*REXX program to solve the problem of Apollonius, named after the Greek*/
|
||||
/*────────── Apollonius of Perga [Pergæus] (circa 262 BC ──► 190 BC).*/
|
||||
w=20; numeric digits w-5 /*width used to display numbers. */
|
||||
c1.x=0; c1.y=0; c1.r=1
|
||||
c2.x=4; c2.y=0; c2.r=1
|
||||
c3.x=2; c3.y=4; c3.r=2
|
||||
call tell 'external tangent:', solveApollonius( 1, 1, 1)
|
||||
call tell 'internal tangent:', solveApollonius(-1, -1, -1)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SOLVEAPOLLONIUS subroutine──────────*/
|
||||
/*───────────────────this code should be covered with a very think tarp.*/
|
||||
solveApollonius: arg s1,s2,s3 /*internal or external tangent ? */
|
||||
/*───────────────────this code should be covered with a very thick tarp.*/
|
||||
solveApollonius: parse arg s1,s2,s3 /*internal or external tangent ? */
|
||||
numeric digits digits()*3 /*reduce rounding: use triple dig*/
|
||||
x1=c1.x; x2=c2.x; x3=c3.x
|
||||
y1=c1.y; y2=c2.y; y3=c3.y
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue