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

Function image_distance

physics/mirror_formulae.py:107–127  ·  view source on GitHub ↗

>>> 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):

(focal_length: float, distance_of_object: float)

Source from the content-addressed store, hash-verified

105
106
107def image_distance(focal_length: float, distance_of_object: float) -> float:
108 """
109 >>> from math import isclose
110 >>> isclose(image_distance(10, 40), 13.33333333)
111 True
112 >>> from math import isclose
113 >>> isclose(image_distance(1.5, 6.7), 1.932692308)
114 True
115 >>> image_distance(0, 0) # doctest: +NORMALIZE_WHITESPACE
116 Traceback (most recent call last):
117 ...
118 ValueError: Invalid inputs. Enter non zero values with respect
119 to the sign convention.
120 """
121
122 if distance_of_object == 0 or focal_length == 0:
123 raise ValueError(
124 "Invalid inputs. Enter non zero values with respect to the sign convention."
125 )
126 image_distance = 1 / ((1 / focal_length) - (1 / distance_of_object))
127 return image_distance

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected