Python中球体的表面积

时间:2014-06-07 14:28:32

标签: python-3.x geometry

我正在尝试编写一个计算长椭球或扁球体表面积的函数。这是我获得公式的位置的链接(http://en.wikipedia.org/wiki/Prolate_spheroid& http://en.wikipedia.org/wiki/Oblate_spheroid)。我想我写错了,但到目前为止这是我的代码;

from math import pi, sqrt, asin, degrees, atanh 

def checkio(height, width):
    height = float(height) 
    width = float(width) 
    my_list = []
    if height == width:
        r = 0.5 * width
        surface_area = 4 * pi * r**2
        surface_area = round(surface_area, 2) 
        my_list.append(surface_area)
    elif height > width: #If spheroid is prolate 
        a = 0.5 * width
        b = 0.5 * height
        e2 = 1 - a**2 / b**2
        e = sqrt(e2) 
        surface_area = 2 * pi * a**2 * (1 + b / (a * e) * asin(e)))
        surface_area = round(surface_area, 2) 
        my_list.append(surface_area) 
    elif height < width: #If spheroid is oblate 
        a = 0.5 * width
        b = 0.5 * height
        e2 = 1 - b**2 / a**2
        e = sqrt(e2) 
        surface_area = 2 * pi * a**2 * (1 + (1 - e2) / e * atanh(e))
        surface_area = round(surface_area, 2)
        my_list.append(surface_area)
    return my_list 

0 个答案:

没有答案