this module contains the functions to calculate the focal length object distance and image distance of a mirror the mirror formula is an equation that relates the object distance u image distance v and focal length f of a spherical mirror it is commonly used in optics to determine the position and characteristics of an image formed by a mirror it is expressed using the formulae 1f 1v 1u where f focal length of the spherical mirror metre v image distance from the mirror metre u object distance from the mirror metre the signs of the distances are taken with respect to the sign convention the sign convention is as follows 1 object is always placed to the left of mirror 2 distances measured in the direction of the incident ray are positive and the distances measured in the direction opposite to that of the incident rays are negative 3 all distances are measured from the pole of the mirror there are a few assumptions that are made while using the mirror formulae they are as follows 1 thin mirror the mirror is assumed to be thin meaning its thickness is negligible compared to its radius of curvature this assumption allows us to treat the mirror as a twodimensional surface 2 spherical mirror the mirror is assumed to have a spherical shape while this assumption may not hold exactly for all mirrors it is a reasonable approximation for most practical purposes 3 small angles the angles involved in the derivation are assumed to be small this assumption allows us to use the smallangle approximation where the tangent of a small angle is approximately equal to the angle itself it simplifies the calculations and makes the derivation more manageable 4 paraxial rays the mirror formula is derived using paraxial rays which are rays that are close to the principal axis and make small angles with it this assumption ensures that the rays are close enough to the principal axis making the calculations more accurate 5 reflection and refraction laws the derivation assumes that the laws of reflection and refraction hold these laws state that the angle of incidence is equal to the angle of reflection for reflection and the incident and refracted rays lie in the same plane and obey snell s law for refraction description and assumptions adapted from https www collegesearch inarticlesmirrorformuladerivation sign convention adapted from https www toppr comaskcontentconceptsignconventionformirrors210189 from math import isclose isclosefocallength10 20 6 66666666666666 true from math import isclose isclosefocallength9 5 6 7 3 929012346 true focallength0 20 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention from math import isclose iscloseobjectdistance30 20 60 0 true from math import isclose iscloseobjectdistance10 5 11 7 102 375 true objectdistance90 0 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention from math import isclose iscloseimagedistance10 40 13 33333333 true from math import isclose iscloseimagedistance1 5 6 7 1 932692308 true imagedistance0 0 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention from math import isclose isclose focal_length 10 20 6 66666666666666 true from math import isclose isclose focal_length 9 5 6 7 3 929012346 true focal_length 0 20 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention from math import isclose isclose object_distance 30 20 60 0 true from math import isclose isclose object_distance 10 5 11 7 102 375 true object_distance 90 0 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention from math import isclose isclose image_distance 10 40 13 33333333 true from math import isclose isclose image_distance 1 5 6 7 1 932692308 true image_distance 0 0 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention
def focal_length(distance_of_object: float, distance_of_image: float) -> float:
    

    if distance_of_object == 0 or distance_of_image == 0:
        raise ValueError(
            "Invalid inputs. Enter non zero values with respect to the sign convention."
        )
    focal_length = 1 / ((1 / distance_of_object) + (1 / distance_of_image))
    return focal_length


def object_distance(focal_length: float, distance_of_image: float) -> float:
    

    if distance_of_image == 0 or focal_length == 0:
        raise ValueError(
            "Invalid inputs. Enter non zero values with respect to the sign convention."
        )
    object_distance = 1 / ((1 / focal_length) - (1 / distance_of_image))
    return object_distance


def image_distance(focal_length: float, distance_of_object: float) -> float:
    

    if distance_of_object == 0 or focal_length == 0:
        raise ValueError(
            "Invalid inputs. Enter non zero values with respect to the sign convention."
        )
    image_distance = 1 / ((1 / focal_length) - (1 / distance_of_object))
    return image_distance