[solved] Need a hint about volume calculation of sphere.

Game development specific discussions.
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

[solved] Need a hint about volume calculation of sphere.

Post by D.J.Peters »

I know the volume of a sphere ;-)
but if i cut a sphere in two individual parts how to calculate the weight/volume of this two parts ?

I need to know how many of a floating sphere are over and under whater.
I know the physics (forces act on the sphere in water and air) only the volume is currently the problem.

The result should be for example 20% are under and 80% over the water line.

water line y = 0
sphere y position = -2.123
sphere radius = 4

How many percent of the sphere are over/under the water line ?

Thank you and sorry about my english.

Joshy
Last edited by D.J.Peters on Jul 08, 2010 17:43, edited 2 times in total.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

(4/3)pi x r^3 x (.20) ??

-Vince
Voltage
Posts: 110
Joined: Nov 19, 2005 7:36
Location: Sydney, Australia
Contact:

Post by Voltage »

Hey Joshy,

I think the English term you are looking for is: "The volume of a dome".

Normally a dome is just half a sphere, which is easy to calculate the volume of. But for other domes, that aren't half spheres you'll need the following:

- http://en.wikipedia.org/wiki/Dome_(mathematics)
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

hello voltage thanx but i'm not sure is it the right you posted.

i think if i get the real percent i can calculate the volume under/over the water line.
It's simple for a box but i don't find the percent for a sphere.

vince can you fix my wrong first try please ?

thank you

Joshy

Code: Select all

function GetPercentUnderWater(WaterLine    as single=0, _
                              SpherePosY   as single=0, _
                              SphereRadius as single=1) as single
  dim as single diameter = SphereRadius*2
  dim as single yup      = SpherePosY+SphereRadius
  dim as single ydown    = SpherePosY-SphereRadius
  if yup<=WaterLine then
    ' complete under the waterline
    return 1.0 ' * 100 = percent
  elseif ydown>=WaterLine then
    ' complete over the waterline
    return 0.0  ' * 100 = percent
  else
    return (WaterLine-ydown)/diameter
  end if
end function


print GetPercentUnderWater(0, 0.0 ,1)*100
print GetPercentUnderWater(0,-0.25,1)*100
print GetPercentUnderWater(0,-0.50,1)*100
print GetPercentUnderWater(0,-0.75,1)*100
print GetPercentUnderWater(0,-2.00,1)*100
sleep
kinem
Posts: 87
Joined: Sep 24, 2008 15:55

Post by kinem »

Prime Productions
Posts: 147
Joined: May 24, 2009 23:13
Location: Texas, United States, Planet Earth
Contact:

Post by Prime Productions »

kinem wrote:Try Google next time.

http://mathforum.org/library/drmath/view/55100.html
Oh, a wise guy, eh?

Just kidding, I don't mean anything by it.
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

hello kinem
you know how many thausend answers i wrote on this forum
without "use google next time" ;-)

A forum is to talk and solve problems and share solutions together.

Joshy
kinem
Posts: 87
Joined: Sep 24, 2008 15:55

Post by kinem »

Give a man an answer, and he can code for a day.

Teach a man to Google, and he can code for a lifetime :)
Voltage
Posts: 110
Joined: Nov 19, 2005 7:36
Location: Sydney, Australia
Contact:

Post by Voltage »

D.J.Peter's has proven his worth on these forums 1 million times over.

I assume that the problem is not his maths, or programming ability, but his English.

Here's another link that I found DJ.

http://answers.yahoo.com/question/index ... 102AAB5kZV

With the specific formula: pi*h/6(3r^2+h^2)

Cheers

Volt
kinem
Posts: 87
Joined: Sep 24, 2008 15:55

Post by kinem »

I didn't doubt DJ's worth or mean him any disrespect, and I resent any implication that I did. My suggestion was honest.

I do agree that the term "dome" was probably what he was missing if he did search first. So that was a good suggestion, Voltage.
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

Hey Joshy,

I've been researching coordinate systems...

http://mathworld.wolfram.com/BicyclideCoordinates.html

Might be useful. I don't know.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Per one of my references the volume of a spherical cap = (pi*h/6*(3*r^2+h^2)).

But it's apparently not valid for h > r, so you would also need to calculate the volume for the full sphere.

Code: Select all

dim as double v1,v2,v3,r=1,h=1,pi=atn(1)*4
'' full sphere
v1 = 4/3*pi*r^3
print v1
print v1/2
print
'' spherical cap
v2 = (pi*h/6*(3*r^2+h^2))
print v2
print
h = 1.001
v2 = (pi*h/6*(3*r^2+h^2))
h = 0.999
v3 = (pi*h/6*(3*r^2+h^2))
print v2+v3
h = 1.25
v2 = (pi*h/6*(3*r^2+h^2))
h = 0.75
v3 = (pi*h/6*(3*r^2+h^2))
print v2+v3

sleep

Code: Select all

 4.18879020478639
 2.094395102393195

 2.094395102393195

 4.188793346379044
 4.385139745635753
kinem
Posts: 87
Joined: Sep 24, 2008 15:55

Post by kinem »

If H is the height of a dome, the volume is pi (r H^2 - (1/3) H^3). That's based on the reference I gave but I have also confirmed this by doing the math.

Note that some references use the distance h from the equator to the bottom of the dome instead. h + H = r

Note special cases:
H=0, V = 0

H = r, V = (2/3) pi r^3 (half sphere)

H = 2 r, V = (4/3) pi r^3 (full sphere)
D.J.Peters
Posts: 8631
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Now i have all infos

thank you all

Joshy
kiyotewolf
Posts: 1009
Joined: Oct 11, 2008 7:42
Location: ABQ, NM
Contact:

Post by kiyotewolf »

rolliebollocks
Master

PostPosted: Jul 08, 2010 4:01 Post subject: Reply with quote
Hey Joshy,

I've been researching coordinate systems...

http://mathworld.wolfram.com/BicyclideCoordinates.html

Might be useful. I don't know.
Holy crap this doesn't look like a coordinate system, it looks like torusii, toruses, torii, whatever.. and .. weird crap..

Coordinate system with a view!

I'm not joking this time, this stuff looks deep, and I don't understand what it could be used for, except maybe higher dimension stuff, even THAT I don't understand either.



~Kiyote!

P.S. To whoever,.. I will try to knock off so many dumb puns.[/quote]
Post Reply