MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / image_distance

Function image_distance

physics/lens_formulae.py:108–131  ·  view source on GitHub ↗

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 (m

(
    focal_length_of_lens: float, object_distance_from_lens: float
)

Source from the content-addressed store, hash-verified

106
107
108def image_distance(
109 focal_length_of_lens: float, object_distance_from_lens: float
110) -> float:
111 """
112 Doctests:
113 >>> from math import isclose
114 >>> isclose(image_distance(50,40), 22.22222222222222)
115 True
116 >>> from math import isclose
117 >>> isclose(image_distance(5.3,7.9), 3.1719696969696973)
118 True
119
120 >>> object_distance(0, 20) # doctest: +NORMALIZE_WHITESPACE
121 Traceback (most recent call last):
122 ...
123 ValueError: Invalid inputs. Enter non zero values with respect
124 to the sign convention.
125 """
126 if object_distance_from_lens == 0 or focal_length_of_lens == 0:
127 raise ValueError(
128 "Invalid inputs. Enter non zero values with respect to the sign convention."
129 )
130 image_distance = 1 / ((1 / object_distance_from_lens) + (1 / focal_length_of_lens))
131 return image_distance

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected