| Bytes | Lang | Time | Link |
|---|---|---|---|
| 099 | APLNARS | 250223T093054Z | Rosario |
| 126 | JavaScript ES7 | 250126T153238Z | Arnauld |
| 232 | Python 3.8 prerelease | 250129T215939Z | BeardedO |
| 137 | APL+WIN | 250127T170252Z | Graham |
| 218 | Maple | 250127T010022Z | dharr |
| 031 | Jelly | 250126T091358Z | Jonathan |
| 066 | Charcoal | 250126T112602Z | Neil |
APL(NARS), 99 chars
{C←≠/¨⍳⍴M←⊃3⍴⊂⍵⋄(4÷⍨√(+/⍵)÷⍨×/+/M×C-I)××/A×C+I×÷A×A←⊃3⍴⊂1+3○4÷⍨¯2○(2×(¯1⌽⍵)×1⌽⍵)÷⍨+/M×M×C-I←=/¨⍳⍴M}
It use I=(identity on ⍴M), and C=(⍴M matrix of 1)-I. Test:
f←{C←≠/¨⍳⍴M←⊃3⍴⊂⍵⋄(4÷⍨√(+/⍵)÷⍨×/+/M×C-I)××/A×C+I×÷A×A←⊃3⍴⊂1+3○4÷⍨¯2○(2×(¯1⌽⍵)×1⌽⍵)÷⍨+/M×M×C-I←=/¨⍳⍴M}
f 28392 21000 25872
3969 4900 4356
f 1 1 1
0.1830127019 0.1830127019 0.1830127019
f 1 2 2
0.309449296 0.2182458366 0.2182458366
f 2 2 3
0.4114378278 0.4114378278 0.2731817602
JavaScript (ES7), 126 bytes
-2 thanks to @l4m2
Expects (a,b,c) and returns an array of 3 floats.
(a,b,c)=>[m=Math,g=r=>1+m.tan(m.acos((r?[a,b,c]=[c,a,b]:x=a+b+c,x/=c+a-b,a*a+b*b-c*c)/2/a/b)/4),0].map(_=>g()*g``/g``/x**.5/4)
Method
For each Malfatti circle radius, the same method g is invoked 3 times to:
compute and return successively \$1+\tan A/4\$, \$1+\tan B/4\$, \$1+\tan C/4\$ in the relevant order
simultaneously compute the expression:
$$x=\frac{a+b+c}{(b+c-a)(c+a-b)(a+b-c)}$$
which allows to compute:
$$\frac{r}{2}=\frac{1}{4\sqrt x}$$
The behavior of g is solely determined by the order of the triplet \$(a,b,c)\$ which is rotated 2 times out of 3.
Commented
Edit: the definition of g has been moved in the array in the last revision.
(a, b, c) => // (a, b, c) = input
[ m = Math, 0, 0 ] // m = alias for Math
.map(_ => // repeat 3 times:
( g = r => // g is a helper function taking a flag r:
1 + m.tan( // compute 1 + the tangent of ...
m.acos( // the inverse cosine of ...
( //
r ? // if r is set:
[a, b, c] = // rotate (a, b, c)
[c, a, b] // to (c, a, b)
: // else:
x = a + b + c, // initialize x to a + b + c
x /= c + a - b, // divide x by c + a - b
a * a + // the actual argument for the
b * b - // inverse cosine is:
c * c // a² + b² - c² ...
) / 2 / a / b // ... divided by 2ab
) / 4 // end of Math.acos(); divide by 4
) // end of Math.tan()
)() // first call to g (r not set)
* g`` // multiply by a 2nd call to g (r set)
/ g`` // divide by a 3rd call to g (r set)
/ x ** .5 / 4 // divide by 4√x
) // end of map()
Python 3.8 (pre-release), 233 232 bytes
from math import*
R=lambda a:(a,a[1:]+a[:1],a[2:]+a[:2])
def D(a):B,C,A=[1+tan(q/4)for q in[acos((x*x+y*y-z*z)/(2*x*y))for x,y,z in R(a)]];return(prod(map(lambda i,j,k:i+j-k,*R(a)))/sum(a))**.5/4*A*B/C
f=lambda x:print(*map(D,R(x)))
How
R=lambda a:(a,a[1:]+a[:1],a[2:]+a[:2])
Rotates through the three variables to produce (a,b,c), (b,c,a), (c,a,b). It seems like this could be shorter.
[1+tan(q/4)for q in[acos((x*x+y*y-z*z)/(2*x*y))for x,y,z in R(a)]]
The nested list comprehension produces the three acos values A, B, and C with the loop in the right and then feeds them into the left hand side to get the three tangents.
prod(map(lambda i,j,k:i+j-k,*R(a)))
Finally we get to use prod for free since we have the from math import*. This save one char when creating the numerator under the r's sqrt.
APL+WIN, 137 bytes
Prompts for a vector of side lengths
m←0 1 2⌽3 3⍴⎕⋄r←0 1 2⌽3 3⍴1+3○.25ׯ2○((m[;2]*2)+(m[;3]*2)-m[;1]*2)÷2××/m[;2 3]⋄(.25×((×/(+/m[;2 3])-m[;1])÷+/m[1;])*.5)×(×/r[;2 3])÷r[;1]
Maple, 218 bytes
proc()s:=x->subs({a=b,b=c,c=a,A=B,B=C,C=A},x);q:=d[A]=r[A]*sqrt((a+b+c)*(b+c-a)/(a+b-c)/(a-b+c));4*r[A]*r[B]=(d[A]+d[B]-c)^2;t:=subs(q,s(q),%);e=subs((a,b,c)=~args,{t,s(t),s(s(t))});eval([r[A],r[B],r[C]],fsolve(e))end;
proc()
s:=x->subs({a=b,b=c,c=a,A=B,B=C,C=A},x); # makes cyclic substitutions
q:=d[A]=r[A]*sqrt((a+b+c)*(b+c-a)/(a+b-c)/(a-b+c)); # Mathworld Eq (12)
4*r[A]*r[B]=(d[A]+d[B]-c)^2; # Mathworld Eq (9)
t:=subs(q,s(q),%); # substitute d[A] and d[B] in Eq (9)
e:=subs((a,b,c)=~args, # substitute numerical values into
{t,s(t),s(s(t))}); # the 3 equations to solve.
eval([r[A],r[B],r[C]],fsolve(e)) # solve and output
end;
Since the arccos and other trig functions in Maple are verbose, I looked for equations that don't use them. The six equations 9-14 on MathWorld are two equations (9 and 12) with the others found from cyclic permutations of the variables. Solving all six equations directly gave too many invalid solutions, e.g., negative d or r values. But substituting d values found from eqns 12-14 into eqns 9-11 and solving these three equations works without additional conditions required. Subscripts 1,2,3 were replaced by A,B,C for golfing purposes.
The default output from fsolve is {r[A]=number, r[B]=number, r[C]=number} and if that were acceptable then the last line could just be fsolve(e), saving 23 bytes.
Jelly, 31 bytes
S_Ḥ
²Ç×÷PHÆA÷4ÆT‘P÷²ƊɓÇP÷SƊ½÷4×
A monadic Link that accepts the three side lengths as a list and yields the three radii.
Try it online! Or see the test-suite.
How?
Just a golfed implementation of the given method.
S_Ḥ - Helper Link: list of integers, L=[x, y, z]
S - sum {L} -> Sum = x+y+z
Ḥ - double {L} -> Doubles = [2x, 2y, 2z]
_ - {Sum} subtract {Doubles} -> [y+z-x, x+z-y, x+y-z]
²Ç×÷PHÆA÷4ÆT‘P÷²ƊɓÇP÷SƊ½÷4× - Main Link: list of integers, T=[a, b, c]
² - square {T} -> [a², b², c²]
Ç - call the Helper Link with {that} -> [b²+c²-a², a²+c²-b², a²+b²-c²]
× - multiply by {T} -> [a(b²+c²-a²), b(a²+c²-b²), c(a²+b²-c²))
P - product {T} -> abc
÷ - divide {these} -> [(b²+c²-a²)÷bc, (a²+c²-b²)÷ac, (a²+b²-c²)÷ab]
H - halve {that} -> [(b²+c²-a²)÷2bc, (a²+c²-b²)÷2ac, (a²+b²-c²)÷2ab]
ÆA - arc-cosine {that} -> [A, B, C]
÷4 - divide {that} by four -> [A÷4, B÷4, C÷4]
ÆT - tangent {that} -> [tan(A÷4), tan(B÷4), tan(C÷4)]
‘ - increment {that} -> [1+tan(A÷4), 1+tan(B÷4), 1+tan(C÷4)]
Ɗ - last three links as a dyad - f(X=that):
P - product {X} -> (1+tan(A÷4))(1+tan(B÷4))(1+tan(C÷4)]
² - square {X} -> [(1+tan(A÷4))², (1+tan(B÷4))², (1+tan(C÷4))²]
÷ - divide {these}
-> Z = [(1+tan(B÷4))(1+tan(C÷4))÷(1+tan(A÷4)),
(1+tan(A÷4))(1+tan(C÷4))÷(1+tan(B÷4)),
(1+tan(A÷4))(1+tan(B÷4))÷(1+tan(C÷4)),
]
ɓ - start a new dyadic chain - f(T, Z)
Ç - call the Helper Link with {T} -> [b+c-a, a+c-b, a+b-c]
Ɗ - last three links as a monad - f(X=that):
P - product {X} -> (b+c-a)×(a+c-b)×(a+b-c)
S - sum {X} -> b+c-a+a+c-b+a+b-c = a+b+c
÷ - divide {those} -> 4r²
½ - square-root {that} -> 2r
÷4 - divide {that} by four -> r÷2
× - multiply {that} by {Z} -> [r(GA), r(GB), r(GC)]
Charcoal, 66 bytes
F³⊞υN≔E∕×υ⁻ΣXυ²⊗Xυ²⊗Πυ∕₂⁻¹Xι²ιθF²UMθ∕⊖₂⊕Xκ²κI×∕Π⊕θX⊕θ²∕₂∕Π⁻Συ⊗υΣυ⁴
Attempt This Online! Link is to verbose version of code. Explanation:
F³⊞υN
Input \$ a \$, \$ b \$ and \$ c \$.
∕×υ⁻ΣXυ²⊗Xυ²⊗Πυ
Calculate \$ \cos A \$, \$ \cos B \$ and \$ \cos C \$ using the cosine rule for triangles...
≔E...∕₂⁻¹Xι²ιθ
... and from those, calculate \$ \tan A \$, \$ \tan B \$ and \$ \tan C \$ using this formula:
$$ \tan \theta = \frac { \sqrt { 1 - \cos^2 \theta } } { \cos \theta } $$
F²UMθ∕⊖₂⊕Xκ²κ
Calculate \$ \tan \frac A 4 \$, \$ \tan \frac B 4 \$ and \$ \tan \frac C 4 \$ using this formula twice:
$$ \tan \frac \theta 2 = \frac { \sqrt { 1 + \tan^2 \theta } - 1 } { \tan \theta } $$
∕₂∕Π⁻Συ⊗υΣυ⁴
Calculate \$ \frac r 2 \$ ...
I×∕Π⊕θX⊕θ²...
... and use that to calculate the desired radii.