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

Function focal_length

physics/mirror_formulae.py:61–81  ·  view source on GitHub ↗

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

(distance_of_object: float, distance_of_image: float)

Source from the content-addressed store, hash-verified

59
60
61def focal_length(distance_of_object: float, distance_of_image: float) -> float:
62 """
63 >>> from math import isclose
64 >>> isclose(focal_length(10, 20), 6.66666666666666)
65 True
66 >>> from math import isclose
67 >>> isclose(focal_length(9.5, 6.7), 3.929012346)
68 True
69 >>> focal_length(0, 20) # doctest: +NORMALIZE_WHITESPACE
70 Traceback (most recent call last):
71 ...
72 ValueError: Invalid inputs. Enter non zero values with respect
73 to the sign convention.
74 """
75
76 if distance_of_object == 0 or distance_of_image == 0:
77 raise ValueError(
78 "Invalid inputs. Enter non zero values with respect to the sign convention."
79 )
80 focal_length = 1 / ((1 / distance_of_object) + (1 / distance_of_image))
81 return focal_length
82
83
84def object_distance(focal_length: float, distance_of_image: float) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected