Mike
Mike

Reputation: 2313

Java calculations for calculating the volume of a cylinder and elliptical cylinder

Here is my calculations for a circular (regular) cylinder

volume = Math.PI * Math.pow(length / 2.0, 2) * depth;  

Here are my calculations for an elliptical cylinder

volume = Math.PI * Math.pow(length * width, 2) * depth;  

When I run it as a circle it comes out fine, but when I run it as an oval it returns a huge number. I'm not sure if my calculations are wrong or what.

Upvotes: 0

Views: 1136

Answers (3)

J T
J T

Reputation: 5156

Mike,

Test your formula against Wolfram Alpha:

http://www.wolframalpha.com/entities/calculators/elliptic_cylinder_volume/1n/ld/39/

Remember that:

  • semi-major axis is length divided by two
  • semi-minor axis is width divided by two
  • Length is the case of wolfram alpha, is actually what you refer to as depth

Upvotes: 0

highBandWidth
highBandWidth

Reputation: 17306

Off the top, the volume for the oval (elliptical cylinder) is not correct dimensionally. It should be

volume = Math.PI * (length * width) / 4.0 * depth;

Upvotes: 2

corsiKa
corsiKa

Reputation: 82589

volume = Math.PI * length * width * depth / 4; // div by 4

It's really (length/2) * (width/2), but we can simplify it to (length * width / 4)

Upvotes: 2

Related Questions