Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Volume of a Spherical Shell

Author
Message
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th Feb 2011 22:51 Edited at: 28th Feb 2011 22:58
I'm useless at maths. I need the following link converting into code that will work in DBPro. I just need the notation changing into code notation. Basically I want to compare an outer radius with an inner radius, and get the volume. Think of it as an igloo. I want that radius to fill the hole in the centre exactly. So every time I compare the shell, it will always fill the hole, no matter what size I have. So the ice of the igloo will always fit the hole dug for the ice. But a spherical igloo, with the hole in the centre.

Thanks.
http://www.emathzone.com/tutorials/geometry/spherical-shell.html

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 23:33
I could be wrong (I'm very tired) but isn't it just:


kaedroho
18
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 1st Mar 2011 00:33 Edited at: 1st Mar 2011 00:37
The volume of a sphere is,



To get the volume of the shell you need to get get the volume of the whole thing, and take away the volume of the hollow area.



this simplifies to:



A slightly different answer to what baxslash got...


Source: http://en.wikipedia.org/wiki/Sphere

Your signature has been erased by a mod please reduce it to no larger than 600 x 120.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Mar 2011 01:19 Edited at: 1st Mar 2011 02:20
Thanks for the replies. This will make life much easier. I suppose if I get the volume of the whole thing, and divide it by 2, I get a shell that will exactly fill the hole?

Which I think is...

4/3 * pi * outer^3 - (4/3 * pi * outer^3) /2

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 10:18 Edited at: 1st Mar 2011 10:18
Quote: "A slightly different answer to what baxslash got..."

I just copied what it had in Pincho Paxton's link



I thought using the diameter looked slightly neater and used one less multiplication operation.

I haven't the faintest idea if it is correct I just provided a direct translation, but the version using the radius is the same.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Mar 2011 14:36 Edited at: 1st Mar 2011 14:42
I just need a bit more maths to start my project. I need to make sure that the hole, and the shell volumes match exactly, so that the shell exactly fills the hole, so I need a way to get the inner radius from the whole radius. Once I have that, I need to keep the hole, and the shell matching no matter what scale I have. These are to be made into a couple of sphere objects, and they are to be particles that collide. Now it is possible for one particle to enter another particle. When two particles are combined, the shell are added together, but the holes are shared (not added together). This means that the volume of the hole no longer matches the combined volume of the shells. I have to get them to match by expanding the holes. It's a scientific project, and most of the maths is beyond me. But once this part works, the rest is a neural network, so self-building. I want to see what happens when these particles start to collide with one another, yet the balance of volume is maintained.



baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 14:51 Edited at: 1st Mar 2011 15:23
Try this:


If you have Matrix Utils this looks neater:


EDIT: There are some redundant brackets in there but they won't slow it down much

EDIT: Without doing all that crazy math you could use this instead (I think...)



Just been checking this and it seems to be right. As it's just a ratio of the original radius it's constant. You might want a more accurate ratio but I doubt you'll need it for what you're doing.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Mar 2011 18:00 Edited at: 1st Mar 2011 18:03
Thanks! That's great! So the shell is a constant. That's good for speed. Any idea how to add the volume of multiple inner shells to get the new total radius? Like when a particle enters another particle?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 18:19
Quote: "Any idea how to add the volume of multiple inner shells to get the new total radius? Like when a particle enters another particle?"

...not sure I understand?

If you know the volume of one shell you can just add it to another, unless they overlap? In that case just use the outer radius and the smallest inner radius.

Maybe you could do a quick illustration?

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Mar 2011 19:08 Edited at: 1st Mar 2011 19:16
Quote: "..not sure I understand?

If you know the volume of one shell you can just add it to another, unless they overlap? In that case just use the outer radius and the smallest inner radius.

Maybe you could do a quick illustration?"


Overlapping particles need to expand the Radius of the outer shell...


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 20:11
Really nice illustration. I get it now

You need to expand the inner and outer radius of the larger shell and at the same time keep the volume of the outer shell the same...

First you need to expand the inner radius enough to make it fit the little shell (I assume it must allow for the full volume of the little sphere both positive and negative). Then you need to work out what the new outer radius is.

I'll take a look first thing tomorrow, busy tonight but the solution is not too complicated.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 1st Mar 2011 20:38 Edited at: 1st Mar 2011 20:39
Quote: "Really nice illustration. I get it now

You need to expand the inner and outer radius of the larger shell and at the same time keep the volume of the outer shell the same...

First you need to expand the inner radius enough to make it fit the little shell (I assume it must allow for the full volume of the little sphere both positive and negative). Then you need to work out what the new outer radius is.

I'll take a look first thing tomorrow, busy tonight but the solution is not too complicated."


Well, I think that the outer shell thins, and the inner shell thickens, and the hole expands, all by the same amount, so that the shells still add up to the total holes. I just didn't draw that part accurately.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2011 10:53 Edited at: 2nd Mar 2011 11:07
Quote: "Well, I think that the outer shell thins, and the inner shell thickens, and the hole expands, all by the same amount, so that the shells still add up to the total holes. I just didn't draw that part accurately."

Yes, actually you explained it much better. That's what I meant. Hard concept to convey

Okay, nearly finished a small demo for you...

EDIT: Here you go. Seems to work just fine!


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2011 11:10
Just realised I used "d3d" plugin, this version only uses matrix util:


Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Mar 2011 18:02
That's fantastic! I will give credit to you, and kaedroho for the maths input.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2011 18:08
No need, glad to help

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Mar 2011 11:48 Edited at: 8th Mar 2011 11:51
Ok I have some of it working now. Watch the YouTube video. I want the colours of the particles to change by scale, and I'm having a problem with it. Here is my bodged code...


What I actually would like to have is a real colour average taken from the largest particle to the smallest. Yet the particles keep scaling up, so the average has to be re-estimated every frame. I would like a smooth transition through every possible colour like a rainbow, from Black (largest) to white (smallest)





http://www.youtube.com/watch?v=ggRxyHjimxM&feature=player_embedded

Thanks... Pincho

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Mar 2011 13:19 Edited at: 8th Mar 2011 13:20
I have found this example. I need to know how to do linear interpolation through the rainbow, from my largest particle to my smallest particle. But I also need Black at the beginning, and white at the end.


Quote: " * Red (web colour) (Hex: #FF0000) (RGB: 255, 0, 0)
* Orange (colour wheel Orange) (Hex: #FF7F00) (RGB: 255, 127, 0)
* Yellow (web colour) (Hex: #FFFF00) (RGB: 255, 255, 0)
* Green (X11) (Electric Green) (HTML/CSS “Lime”) (Colour wheel green) (Hex: #00FF00) (RGB: 0, 255, 0)
* Blue (web colour) (Hex: #0000FF) (RGB: 0, 0, 255)
* Indigo (Electric Indigo) (Hex: #6600FF) (RGB: 102, 0, 255)
* Violet (Electric Violet) (Hex: #8B00FF) (RGB: 139, 0, 255)

Between each colour make linear interpolation."


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2011 13:47
Not sure if there's a better way or not but I would use the rgb values as they are easiest to manipulate here. Just working on a quick example of how that might work...

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Mar 2011 14:42 Edited at: 8th Mar 2011 14:45
Here, try this. Might help



EDIT: Diggsey posted a shader that might interest you on the Box2D Program Announcements thread. It's designed to create a 'water' effect but coult work nicely for your program... (second to last poast at the moment)

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Mar 2011 00:43
Thanks! I am unsure how it works with the particles, but I will try it out.

Thanks for the shader, but I'm trying to make this self building, like a Neural Network. Although I'm cheating with the colours.

Login to post a reply

Server time is: 2026-07-15 03:40:11
Your offset time is: 2026-07-15 03:40:11