Tag Archives: wolframalpha

Calculate Surface Area and Volume of a Sphere

Actionscript:
  1. var rad:Number = 1;
  2.  
  3. var surfaceArea:Number = sphereSurfaceArea(rad);
  4. var volume:Number = sphereVolume(rad)
  5. trace("surface area: ", surfaceArea);
  6. trace("volume:", volume);
  7. trace("volume / surface area:", volume / surfaceArea);
  8.  
  9. function sphereSurfaceArea(r:Number):Number{
  10.     return 4 * Math.PI * r * r;
  11. }
  12.  
  13. function sphereVolume(r:Number):Number{
  14.     return r * r * r * (4.0/3.0) * Math.PI;
  15. }
  16.  
  17. /*outputs:
  18. surface area:  12.566370614359172
  19. volume: 4.1887902047863905
  20. volume / surface area: 0.3333333333333333
  21. */

Last night I was feeling curious about sphere volume and sphere surface area... I used WolframAlpha to find the neccessary equations and then wrote the above code snippet...

Check out how WolframAlpha does it:
surface area of a sphere
surface area of a sphere with radius 10
sphere volume
sphere volume with radius 10

Posted in Math, misc | Also tagged , , | 2 Comments