开发者

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;  
开发者_如何学C

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.


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)


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;


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜