コード例 #1
0
def cylinder_surface_area(radius, height) -> Unit("m²"):
    """
    Compute the surface area (side + top + bottom)
    """
    radius = normalize_numeric(radius)
    height = normalize_numeric(height)
    return cylinder_side_surface_area(radius, height) + 2 * circle_area(radius)
コード例 #2
0
def cylinder_side_surface_area(radius, height) -> Unit("m²"):
    """
    Compute the surface area of the side (also called ")
    """
    radius = normalize_numeric(radius)
    height = normalize_numeric(height)
    return 2 * math.pi * radius * height
コード例 #3
0
def cylinder_volume(radius, height) -> Unit("m³"):
    """
    Compute the volume of a cylinder by its radius and height
    """
    radius = normalize_numeric(radius)
    height = normalize_numeric(height)
    return math.pi * (radius**2) * height
コード例 #4
0
def hollow_cylinder_inner_radius_by_volume(outer_radius, volume, height) -> Unit("m"):
    """
    Given the outer radius, the height and the inner radius of a hollow cylinder,
    compute the inner radius
    """
    outer_radius = normalize_numeric(outer_radius)
    volume = normalize_numeric(volume)
    height = normalize_numeric(height)
    # Wolfram Alpha: solve V=(pi*o²*h)-(pi*i²*h) for i
    term1 = np.pi*height*(outer_radius**2)-volume
    # Due to rounding errors etc, term1 might become negative.
    # This will lead to sqrt(-x) => NaN but we actually treat it as a zero result
    if term1 < 0.:
        return 0
    # Default case
    return np.sqrt(term1)/(np.sqrt(np.pi) * np.sqrt(height))
コード例 #5
0
def circle_circumference(radius) -> Unit("m"):
    """
    Compute the circumference of a circle from its radius
    """
    radius = normalize_numeric(radius)
    return 2. * math.pi * radius
コード例 #6
0
def circle_area(radius) -> Unit("m²"):
    """
    Compute the enclosed area of a circle from its radius
    """
    radius = normalize_numeric(radius)
    return math.pi * radius**2
コード例 #7
0
def hollow_cylinder_volume(outer_radius, inner_radius, height) -> Unit("m³"):
    """
    Compute the volume of a hollow cylinder by its height and the inner and outer radii
    """
    return cylinder_volume(outer_radius, height) - cylinder_volume(inner_radius, height)