this module has functions which calculate focal length of lens distance of image from the lens and distance of object from the lens the above is calculated using the lens formula in optics the relationship between the distance of the image v the distance of the object u and the focal length f of the lens is given by the formula known as the lens formula the lens formula is applicable for convex as well as concave lenses the formula is given as follows 1f 1v 1u where f focal length of the lens in meters v distance of the image from the lens in meters u distance of the object from the lens in meters to make our calculations easy few assumptions are made while deriving the formula which are important to keep in mind before solving this equation the assumptions are as follows 1 the object o is a point object lying somewhere on the principle axis 2 the lens is thin 3 the aperture of the lens taken must be small 4 the angles of incidence and angle of refraction should be small sign convention is a set of rules to set signs for image distance object distance focal length etc for mathematical analysis of image formation according to it 1 object is always placed to the left of lens 2 all distances are measured from the optical centre of the mirror 3 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 4 distances measured along yaxis above the principal axis are positive and that measured along yaxis below the principal axis are negative note sign convention can be reversed and will still give the correct results reference for sign convention https www toppr comaskcontentconceptsignconventionforlenses210246 reference for assumptions https testbook comphysicsderivationoflensmakerformula doctests from math import isclose isclosefocallengthoflens10 4 6 666666666666667 true from math import isclose isclosefocallengthoflens2 7 5 8 5 0516129032258075 true focallengthoflens0 20 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention doctests from math import isclose iscloseobjectdistance10 40 13 333333333333332 true from math import isclose iscloseobjectdistance6 2 1 5 1 9787234042553192 true objectdistance0 20 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention doctests from math import isclose iscloseimagedistance50 40 22 22222222222222 true from math import isclose iscloseimagedistance5 3 7 9 3 1719696969696973 true objectdistance0 20 doctest normalizewhitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention doctests from math import isclose isclose focal_length_of_lens 10 4 6 666666666666667 true from math import isclose isclose focal_length_of_lens 2 7 5 8 5 0516129032258075 true focal_length_of_lens 0 20 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention doctests from math import isclose isclose object_distance 10 40 13 333333333333332 true from math import isclose isclose object_distance 6 2 1 5 1 9787234042553192 true object_distance 0 20 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention doctests from math import isclose isclose image_distance 50 40 22 22222222222222 true from math import isclose isclose image_distance 5 3 7 9 3 1719696969696973 true object_distance 0 20 doctest normalize_whitespace traceback most recent call last valueerror invalid inputs enter non zero values with respect to the sign convention
def focal_length_of_lens(
    object_distance_from_lens: float, image_distance_from_lens: float
) -> float:
    

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


def object_distance(
    focal_length_of_lens: float, image_distance_from_lens: float
) -> float:
    

    if image_distance_from_lens == 0 or focal_length_of_lens == 0:
        raise ValueError(
            "Invalid inputs. Enter non zero values with respect to the sign convention."
        )

    object_distance = 1 / ((1 / image_distance_from_lens) - (1 / focal_length_of_lens))
    return object_distance


def image_distance(
    focal_length_of_lens: float, object_distance_from_lens: float
) -> float:
    
    if object_distance_from_lens == 0 or focal_length_of_lens == 0:
        raise ValueError(
            "Invalid inputs. Enter non zero values with respect to the sign convention."
        )
    image_distance = 1 / ((1 / object_distance_from_lens) + (1 / focal_length_of_lens))
    return image_distance