Volume of a bead with square hole- Program approach?
|
06-06-2020, 10:43 PM
(This post was last modified: 06-07-2020 08:30 PM by DM48.)
Post: #1
|
|||
|
|||
Volume of a bead with square hole- Program approach?
Description
1 - We have sphere of radius R with rectangular prism removed from it. Centerline of prism includes center of sphere. 2 - Length of one side (along x axis) of rectangle is a length of another side (along y axis) is b. 3 - The following schematic represents cross-sections of sphere with the void in 3 planes. The problem is to find the volume of sphere with the rectangular prism removed through center. Solution 1 - Volume is found by subtracting volume of prism with spherical top and bottom from volume of sphere. \( V=V_{sphere}-V_{prism}=\frac{4}{3}\,\pi \, r^{3}-V_{prism} \) 2 - The prism volume can be found by integration. For this purpose, let's divide the prism in 8 parts of equal volume the same way the simple prism is divided. 3 - The volume of part of prism with spherical ends can be found by integrating equation which describes upper part of sphere’s surface (the one which has positive z coordinates). The equation in Descartes coordinates is z(x,y)=√(r^2-x^2-y^2 ), assuming that sphere center is point 0,0,0. So we can write: Descartes coordinates \( z(x,y)=\sqrt{r^2-x^2-y^2} \) \( V_{prism}=8\int_{0}^{\frac{b}{2}}\int_{0}^{\frac{a}{2}}\sqrt{r^2-x^2-y^2}\,dx\,dy \) \( V_{prism}=4\int_{0}^{\frac{b}{2}}(r^2-y^2)\,arcsin\left (\frac{a}{2\sqrt{r^2-y^2}} \right )\,dy\,+2a\int_{0}^{\frac{b}{2}}\sqrt{r^2-\frac{a^2}{4}-y^2}\,\,dy \) \( V_{prism} = 4\int_{0}^{\frac{b}{2}}\left ( r^2-y^2 \right )\,arcsin\left ( \frac{a}{2\sqrt{r^2-y^2}} \right )\,dy\,+\,\frac{a}{4}\left ( 4r^2-a^2 \right )arcsin\left ( \frac{b}{\sqrt{4r^2-a^2}} \right )\,+\,\frac{ab}{4}\sqrt{4r^2-a^2-b^2} \) 4 - The integral in the right side of equation above can be represented as: \( \int_{0}^{\frac{b}{2}}\left ( r^2-y^2 \right )\,arcsin\,\left ( \frac{a}{2\sqrt{r^2-y^2}} \right )\,dy \) Next part will take time and I'm not sure I can do it. Also, unsure if this is correct but it gets us going in a direction. I wanted to push this out to get opinions. I will rework through this several more times and see what I come up with. Best way to proceed on a program like this with Free42/DM42? Hoping for Werner and Albert to chime in. HP48GX, HP42s and DM42. |
|||
06-07-2020, 02:20 AM
Post: #2
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Hi, DM48
Very nice graph ! I would try something concrete, say R=10, a=b=2 Rough estimating the square hole volume, we have (a*b)*(2*R) = 80 (over-estimated) Now, assuming the hole is circular, with radius r = 1, h = sqrt(R^2-r^2) Circular hole volume (bead formula) = 4/3 pi (R^3 - h^3) ≈ 62.674510653 Scale-up the hole to rectangular, by 4/pi, we have 79.7996654104 This number should still be over-estimated ... For lower bound, we do a rectangular column = (a*b)*(2*h) ≈ 79.5989949685 Hole volume should be inside range = (79.5989949685, 79.7996654104) ≈ 79.699 ± 0.100 |
|||
06-07-2020, 05:37 PM
(This post was last modified: 06-10-2020 06:42 PM by Albert Chan.)
Post: #3
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Code: function hv2(r,a,b) -- assumed (2r)^2 >= a^2 + b^2 lua> hv2(10,2,2) 79.73270765594205 lua> hv2(10,2,4) 158.65795312357352 lua> hv2(10,2,8) 310.69959533330837 lua> hv2(10,2,16) 561.679011610526 Update: replaced atan(y/x) with atan2(y, x) |
|||
06-07-2020, 05:44 PM
Post: #4
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
(06-06-2020 10:43 PM)DM48 Wrote: \( V_{prism} = 4\int_{0}^{\frac{b}{2}}\left ( r^2-y^2 \right )\,arcsin\left ( \frac{a}{2\sqrt{r^2-y^2}} \right )\,dy\,+\,\frac{a}{4}\left ( 4r^2-a^2 \right )arcsin\left ( \frac{b}{\sqrt{4r^2-a^2}} \right )\,+\,\frac{ab}{4\sqrt{4r^2-a^2-b^2}} \) Last term were off, \(\sqrt{4r^2-a^2-b^2}\) should up in the numerator |
|||
06-07-2020, 08:32 PM
(This post was last modified: 06-07-2020 09:28 PM by DM48.)
Post: #5
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Albert, thank you. I have updated the post to fix the error.
HP48GX, HP42s and DM42. |
|||
06-09-2020, 03:52 PM
(This post was last modified: 06-09-2020 06:19 PM by DM48.)
Post: #6
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Working this another way, I will post my notes soon, I get a total volume of 4109.057 in^3 if the sphere has a radius of 10", and the rectangle is 2" x 2".
----- If you ignore the round edges on the hole, Vsphere = 4188.79 in^3 and Vrect = 80 in^3 = 4108.79 in^3 HP48GX, HP42s and DM42. |
|||
06-09-2020, 09:45 PM
Post: #7
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
I cheated, and solve with Mathematica.
This time, I scaled everything by 2, to eliminate the 8x in front of hole volume. > f1 = Integrate[Sqrt[d^2-x^2-y^2],{x,0,a}] \(\frac{a\,{\sqrt{-a^2 + d^2 - y^2}} - d^2\,\arctan (\frac{a\,{\sqrt{-a^2 + d^2 - y^2}}}{a^2 - d^2 + y^2}) + y^2\,\arctan (\frac{a\,{\sqrt{-a^2 + d^2 - y^2}}}{a^2 - d^2 + y^2})}{2}\) > f2 = Integrate[f1, y] // Expand; > f2 /. y -> 0 // Simplify → 0 > f2 = f2 /. y -> b (* dy is integrated from 0 to b *) \(\frac{a\,b\,{\sqrt{-a^2 - b^2 + d^2}}}{3} \\ + \frac{b^3\,\arctan (\frac{a\,{\sqrt{-a^2 - b^2 + d^2}}}{a^2 + b^2 - d^2})}{6} - \frac{b\,d^2\,\arctan (\frac{a\,{\sqrt{-a^2 - b^2 + d^2}}}{a^2 + b^2 - d^2})}{2}\\ + \frac{a^3\,\arctan (\frac{b\,{\sqrt{-a^2 - b^2 + d^2}}}{a^2 + b^2 - d^2})}{6} - \frac{a\,d^2\,\arctan (\frac{b\,{\sqrt{-a^2 - b^2 + d^2}}}{a^2 + b^2 - d^2})}{2}\\ \\ - \frac{i}{6}\,d^3\,\log (\frac{6\,{\sqrt{-a^2 - b^2 + d^2}}} {a\,d^3\,\left( -2\,b + 2\,d \right) } + \frac{3\,i \,\left( -\left( a^2\,d \right) - b\,d^2 + d^3 \right) } {a^2\,d^4\,\left( -b + d \right) }) + \frac{i}{6}\,d^3\,\log (\frac{-6\,{\sqrt{-a^2 - b^2 + d^2}}} {a\,\left( -2\,b - 2\,d \right) \,d^3} + \frac{3\,i \,\left( -\left( a^2\,d \right) + b\,d^2 + d^3 \right) } {a^2\,d^4\,\left( b + d \right)})\) > f2 /. {d->20, a->2, b->2} // N → 79.7327 + 0. I f2 is already hole volume formula, but it is best if we simplify, and remove the imag. part. log(z) = log(|z|) + i * args(z), args(z) = atan(z.imag / z.real) > f3 = Part[f2,-2,-1,-1] → \(\frac{6\,{\sqrt{-a^2 - b^2 + d^2}}}{a\,d^3\,\left( -2\,b + 2\,d \right) } + \frac{3\,i \,\left( -\left( a^2\,d \right) - b\,d^2 + d^3 \right) } {a^2\,d^4\,\left( -b + d \right)}\) > f4 = Part[f2,-1,-1,-1] → \(\frac{-6\,{\sqrt{-a^2 - b^2 + d^2}}} {a\,\left( -2\,b - 2\,d \right) \,d^3} + \frac{3\,i \,\left( -\left( a^2\,d \right) + b\,d^2 + d^3 \right) } {a^2\,d^4\,\left( b + d \right) }\) > t3 = Part[f3,2]/I / Part[f3,1] // Simplify → \(\frac{-a^2 + d\,\left( -b + d \right) }{a\,{\sqrt{-a^2 - b^2 + d^2}}}\) > t4 = Part[f4,2]/I / Part[f4,1] // Simplify → \(\frac{-a^2 + d\,\left( b + d \right) }{a\,{\sqrt{-a^2 - b^2 + d^2}}}\) Using identity, tan(x-y) = (tan(x) - tan(y)) / (1 + tan(x) tan(y)), combine tan(2 angles) > t34 = (t3 - t4) / (1 + t3 t4) // Simplify → \(\frac{2 a b d \sqrt{-a^2 - b^2 + d^2}} {d^2 (b^2-d^2) + a^2 (b^2 + d^2)}\) > hv = f2 - Part[f2,{-2,-1}] + d^3/6 ArcTan[t34] // Simplify Result is still messy. Let k = √(d^2 - a^2 - b^2), and expanding √(k²) as k: > hv2 = hv /. b^2 -> d^2 - a^2 - k^2 // Simplify // PowerExpand \(\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}\) > hv2 /. {a->2, b->2, d->20, k->Sqrt[400-4-4]} // N → 79.7327 |
|||
06-09-2020, 11:14 PM
Post: #8
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
My new way is simpler I believe. I will type it in tonight. I admire the work you put into that LaTeX entry. :-)
HP48GX, HP42s and DM42. |
|||
06-10-2020, 12:45 AM
Post: #9
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
How many Angels can dance on the surface of that square hole?
With and without social distancing. |
|||
06-10-2020, 01:33 AM
Post: #10
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Problem: What is the volume of a sphere of radius r, with a rectangular hole (with edge lengths x and y) passing through the center?
Figure 1: Cross-sections through the center of the sphere, with horizontal and vertical spherical caps and their intersections. Solution. The remaining volume of the sphere, with the rectangular hole removed, can be calculated as follows \( V = 2V_{1} + 2V_{2} - 4\left ( V_x + V_y \right ) \) where \(V_1\), \(V_2\), \(V_x\) and \(V_y\) are the volumes corresponding to the cross-section areas in Figure 1. With the formulas for the individual volumes derived in the following sections, and with \( b = \sqrt{r^2-\frac{x^2+y^2}{4}} \) , the formula for the total volume is \(V = \frac{2\pi}{3}\left ( r-\frac{x}{2} \right )^2\left ( 2r+\frac{x}{2} \right )+\frac{2\pi}{3}\left ( r-\frac{y}{2} \right )^2\left ( 2r+\frac{y}{2} \right )-\frac{2bxy}{3}-\frac{8r^3}{3}\left ( arctan\left ( \frac{bx}{ry} \right )+arctan\left ( \frac{by}{rx} \right ) \right )-2x\left ( \frac{x^2}{12}-r^2 \right )arctan\left ( \frac{2b}{y} \right )-2y\left ( \frac{y^2}{12}-r^2 \right )arctan\left ( \frac{2b}{x} \right ) \) Figure 2: Cross-section through the center of the sphere, with α and d as in the paper Volumes \(V_1\) and \(V_2\). \(V_1\) and \(V_2\) correspond to spherical caps (see e.g. Wikipedia page on spherical caps), with heights \( h_1 = r − \frac{x}{2} \) and \( h_2 = r − \frac{y}{2} \) , respectively. Their volumes are \(V_1=\frac{\pi h_1^2}{3}\left ( 3r-h_1 \right )=\frac{\pi}{3}\left ( r-\frac{x}{2} \right )^2\left ( 2r+\frac{x}{2} \right )\) \(V_2=\frac{\pi h_2^2}{3}\left ( 3r-h_2 \right )=\frac{\pi}{3}\left ( r-\frac{y}{2} \right )^2\left ( 2r+\frac{y}{2} \right )\) Volumes \(V_x\) and \(V_y\). A formula for the volume of segments of this type was derived in Section 4.3 of the paper Exact calculation of the overlap volume of spheres and mesh elements by Severin Strobl, Arno Formella and Thorsten P ̈oschel (Journal of Computational Physics, Volume 311, 2016, link). The relevant section is inserted at the end of this document (Figure 3). In our case, sin(α), cos(α) and d can be calculated by considering the small blue triangle (see Figure 2): The edge lengths of this triangle are x2 and y2 and the angle between them is a right angle, so \(sin\left ( \alpha \right )=\frac{y}{2d}\;\;, cos\left( \alpha \right)=\frac{x}{2d}\;\; and\;\;d=\sqrt{\frac{x^2+y^2}{4}}\) With these equations, we can translate the notation of equation (5) of the paper into terms involving only r, x and y (and, for simplicity of notation, b): \(a=d\;sin\left ( \alpha \right )\;=\frac{y}{2}\;,\) \(b = \sqrt{r^2-d^2}\;=\;\sqrt{r^2-\frac{x^2+y^2}{4}}\;,\) \(c=d\;cos\left ( \alpha \right )=\;\frac{x}{2}\) \(V_y=\frac{abc}{3}+a\left ( \frac{a^2}{3}-r^2 \right )arctan\left ( \frac{b}{c} \right )+\frac{2r^3}{3}arctan\left ( \frac{b\;sin\left( \alpha \right)}{r\;cos\left ( \alpha \right )} \right ) =\frac{bxy}{12}+\frac{y}{2}\left ( \frac{y^2}{12}-r^2 \right )arctan\left ( \frac{2b}{x} \right )+\frac{2r^3}{3}arctan\left ( \frac{by}{rx}\right )\) with \(b = \sqrt{r^2-\frac{x^2+y^2}{4}}\) By swapping x and y in the formula for Vy, we can derive the corresponding formula for \(V_x\): \(V_x=\frac{bxy}{12}+\frac{x}{2}\left ( \frac{x^2}{12}-r^2 \right )arctan\left ( \frac{2b}{y} \right )+\frac{2r^3}{3}arctan\left ( \frac{bx}{ry}\right )\) with \(b = \sqrt{r^2-\frac{x^2+y^2}{4}}\) Relevant section (4.3) of Exact calculation of the overlap volume of spheres and mesh elements by Severin Strobl, Arno Formella and Thorsten Po ̈schel (Journal of Computational Physics, Volume 311, 2016, link) HP48GX, HP42s and DM42. |
|||
06-10-2020, 09:22 AM
Post: #11
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
This is fantastic.
A quick transcript to a 42 program: Code: 00 { 180-Byte Prgm } XEQ "RBV" 10 R 2 X 2 Y R/S -> 4109.05749713 RCL "R" 3 Y^X PI x 4 x 3 / X<>Y - -> 79.7327076559 Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
06-10-2020, 01:52 PM
Post: #12
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
I'm glad I understand a lot more of your program. I am learning!
How can I set my calc to RAD and back to DEG from within a running program. Would be nice to have the program change to RAD before running if necessary, and then back to whatever it was. Clearing Flag 43 is not allowed, "Restricted Operation." Is this possible? Reading through the program I see that Complex does more than make a Complex number. It's also assembling a Matrix or Vector. ABS finds the magnitude of the Vector [ X Y]. Interesting! I didn't think about using Complex number formats to do that. HP48GX, HP42s and DM42. |
|||
06-10-2020, 01:58 PM
Post: #13
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
(06-10-2020 01:52 PM)DM48 Wrote: How can I set my calc to RAD and back to DEG from within a running program. Would be nice to have the program change to RAD before running if necessary, and then back to whatever it was. The DEG, RAD and GRAD commands in the MODES menu are programmable. There are only 10 types of people in this world. Those who understand binary and those who don't. |
|||
06-10-2020, 01:59 PM
(This post was last modified: 06-10-2020 02:22 PM by DM48.)
Post: #14
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
(06-10-2020 01:58 PM)grsbanks Wrote:(06-10-2020 01:52 PM)DM48 Wrote: How can I set my calc to RAD and back to DEG from within a running program. Would be nice to have the program change to RAD before running if necessary, and then back to whatever it was. Thank you. HP48GX, HP42s and DM42. |
|||
06-10-2020, 02:06 PM
Post: #15
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
(06-10-2020 01:59 PM)DM48 Wrote:(06-10-2020 01:58 PM)grsbanks Wrote: The DEG, RAD and GRAD commands in the MODES menu are programmable. Especially as the 48S/SX/G/GX has the same ability The flags are, however, useful for determining programatically which mode is currently active. There are only 10 types of people in this world. Those who understand binary and those who don't. |
|||
06-10-2020, 06:32 PM
(This post was last modified: 06-10-2020 06:33 PM by DM48.)
Post: #16
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
(06-10-2020 02:06 PM)grsbanks Wrote:(06-10-2020 01:59 PM)DM48 Wrote: Thank you. I have to stop over thinking these things... So true. My minor tweak to Werner's program doing the calc in RAD and then switching back to degrees. Code: 00 { 186-Byte Prgm } HP48GX, HP42s and DM42. |
|||
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})\;-\; 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)\) 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 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 |
|||
06-11-2020, 06:55 AM
Post: #18
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
And the corresponding 42-style program!
Since the formula has gotten relatively simple, I decided to go for a solver program: Code: 00 { 106-Byte Prgm } Use with shift-SOLVER, select RBV, enter 3 values and then press the variable you want to solve for. For subsequent runs you need only enter the values that have changed. For those who insist on typing it all in: do a 0 STO "var" for each variable used by the program (var=a,b,d,d2,k). Then you can select the variable from the menu when using STO etc. Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
06-11-2020, 02:28 PM
(This post was last modified: 06-11-2020 08:17 PM by DM48.)
Post: #19
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
\(\frac{4}{3}+\left ( -2b^2\sqrt{a^2-2b^2}\;a^3\pi+2a^3\;arccot \left( \frac{a\sqrt{a^2-2b^2}}{b^2} \right)+2b\left(-3a^2+b^2 \right )arctan\left(\frac{b}{\sqrt{a^2-2b^2}} \right ) \right )\)
Another solution by someone else. This assumes (I think) a = radius of sphere and b = square dimension (no rectangle solution). HP48GX, HP42s and DM42. |
|||
06-11-2020, 04:48 PM
(This post was last modified: 06-11-2020 06:28 PM by Albert Chan.)
Post: #20
|
|||
|
|||
RE: Volume of a bead with square hole- Program approach?
Hi, DM48
Dimensional analysis shows the formula is definitely wrong, with Length^6 for first term. Yes, a = radius of sphere, but b was half the length of square. I corrected your formula, and rewrite as volume of sphere - square hole \(\frac{4}{3}\pi a^3 - \frac{8}{3} \left (b^2\sqrt{a^2-2b^2} -a^3\;arctan \left( \frac{b^2}{a\sqrt{a^2-2b^2}} \right) +b\left(3a^2-b^2\right )arctan\left(\frac{b}{\sqrt{a^2-2b^2}} \right ) \right )\) Note, formula for square hole, except for a factor of 8, is same as my code. My formula doubled up all dimensions, diameter instead of radius, and length, width for rectangle. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)