Post Reply 
Volume of a bead with square hole- Program approach?
06-10-2020, 09:31 PM (This post was last modified: 11-05-2023 02:07 PM by Albert Chan.)
Post: #17
RE: Volume of a bead with square hole- Program approach?
(06-09-2020 09:45 PM)Albert Chan Wrote:  \(\Large \frac{2abk\; -\; \left( b^3 - 3bd^2 \right) \arctan (\frac{a}{k})\;-\;
\left( a^3 - 3ad^2 \right)\arctan (\frac{b}{k})\;-\;
d^3\arctan (\frac{2abdk}
{a^4 + d^2k^2 + a^2\left( -d^2 + k^2 \right) })}{6}\)

I just noticed the last big arctan mess can be simplified with half-angle formula

In[1]:= t = (a b) / (d k);
In[2]:= x = 2 t / (1 - t^2) // Simplify     → \(\frac{2\,a\,b\,d\,k}{-\left( a^2\,b^2 \right) + d^2\,k^2}\)

Numerator matched exactly, now check the denominator ...

In[3]:= Denominator[x] /. b^2 -> d^2 - a^2 - k^2 // Expand     → \(a^4 - a^2\,d^2 + a^2\,k^2 + d^2\,k^2\)

→ \(\arctan (\frac{2abdk}{a^4 + d^2k^2 + a^2\left( -d^2 + k^2 \right) })
= 2 \arctan \left({a b \over d k}\right)\) Smile

This is my revised Lua code. I use diameter this time, to match the quoted formula.

Code:
function hv2(d,a,b) -- sphere, rectanglar hole removed volume
    local d2, a2, b2 = d*d, a*a, b*b
    local k = sqrt(d2 - a2 - b2)
    d = a*b*k - d*d2*atan((a*b)/(d*k))
    return (2*d + a*(3*d2-a2)*atan(b/k) + b*(3*d2-b2)*atan(a/k)) / 6
end

lua> hv2(20,2,2)
79.73270765594204
lua> hv2(20,2,4)
158.6579531235735
lua> hv2(20,2,8)
310.6995953333083
lua> hv2(20,2,16)
561.6790116105259
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Volume of a bead with square hole- Program approach? - Albert Chan - 06-10-2020 09:31 PM



User(s) browsing this thread: 1 Guest(s)