Calculate the volume of the spherical cap. >>> vol_spherical_cap(1, 2) 5.235987755982988 >>> vol_spherical_cap(1.6, 2.6) 16.621119532592402 >>> vol_spherical_cap(0, 0) 0.0 >>> vol_spherical_cap(-1, 2) Traceback (most recent call last): ... ValueError
(height: float, radius: float)
| 33 | |
| 34 | |
| 35 | def vol_spherical_cap(height: float, radius: float) -> float: |
| 36 | """ |
| 37 | Calculate the volume of the spherical cap. |
| 38 | |
| 39 | >>> vol_spherical_cap(1, 2) |
| 40 | 5.235987755982988 |
| 41 | >>> vol_spherical_cap(1.6, 2.6) |
| 42 | 16.621119532592402 |
| 43 | >>> vol_spherical_cap(0, 0) |
| 44 | 0.0 |
| 45 | >>> vol_spherical_cap(-1, 2) |
| 46 | Traceback (most recent call last): |
| 47 | ... |
| 48 | ValueError: vol_spherical_cap() only accepts non-negative values |
| 49 | >>> vol_spherical_cap(1, -2) |
| 50 | Traceback (most recent call last): |
| 51 | ... |
| 52 | ValueError: vol_spherical_cap() only accepts non-negative values |
| 53 | """ |
| 54 | if height < 0 or radius < 0: |
| 55 | raise ValueError("vol_spherical_cap() only accepts non-negative values") |
| 56 | # Volume is 1/3 pi * height squared * (3 * radius - height) |
| 57 | return 1 / 3 * pi * pow(height, 2) * (3 * radius - height) |
| 58 | |
| 59 | |
| 60 | def vol_spheres_intersect( |
no outgoing calls
no test coverage detected