Surface Area of a Spheroid in Python
Posted
by
user3678321
on Stack Overflow
See other posts from Stack Overflow
or by user3678321
Published on 2014-06-07T14:28:32Z
Indexed on
2014/06/07
15:24 UTC
Read the original article
Hit count: 193
python-3.x
|geometry
I'm trying to write a function that calculates the surface area of a prolate or oblate spheroid. Here's a link to where I got the formulas (http://en.wikipedia.org/wiki/Prolate_spheroid & http://en.wikipedia.org/wiki/Oblate_spheroid). I think I've written them wrong, but here is my code so far;
from math import pi, sqrt, asin, degrees, tanh
def checkio(height, width):
height = float(height)
width = float(width)
lst = []
if height == width:
r = 0.5 * width
surface_area = 4 * pi * r**2
surface_area = round(surface_area, 2)
lst.append(surface_area)
elif height > width: #If spheroid is prolate
a = 0.5 * width
b = 0.5 * height
e = 1 - a / b
surface_area = 2 * pi * a**2 * (1 + b / a * e * degrees(asin**-1(e)))
surface_area = round(surface_area, 2)
lst.append(surface_area)
elif height < width: #If spheroid is oblate
a = 0.5 * height
b = 0.5 * width
e = 1 - b / a
surface_area = 2 * pi * a**2 * (1 + 1 - e**2 / e * tanh**-1(e))
surface_area = round(surface_area, 2)
lst.append(surface_area, 2)
return lst
© Stack Overflow or respective owner