You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
955 B

import math
class Sphere:
def __init__(self, radius, center):
self.radius = radius
self.center = center
# specify class for the input parameters
def caseSpheresBOnAFace(rA, rB):
#intersection:
rAsq = rA**2
rBsq = rB**2
crownHeightA = rBsq / (2 * rA)
crownHeightB = rB - crownHeightA
crownVolumeA = math.pi * crownHeightA**2 * (3 * rA - crownHeightA) / 3
crownVolumeB = math.pi * crownHeightB**2 * (3 * rB - crownHeightB) / 3
volumeInter = crownVolumeA + crownVolumeB
#union:
volumeA = 4/3 * math.pi * rAsq * rA
volumeB = 4/3 * math.pi * rBsq * rB
volumeUnion = volumeA + volumeB - volumeInter
#difference:
volumeDiff = volumeA - volumeInter
return volumeInter, volumeUnion, volumeDiff
if __name__=="__main__":
volumeInter, volumeUnion, volumeDiff = caseSpheresBOnAFace(800000, 1000)
print("volumeInter = ", volumeInter)
print("volumeUnion = ", volumeUnion)
print("volumeDiff = ", volumeDiff)