-
-
Notifications
You must be signed in to change notification settings - Fork 46k
/
mirror_formulae.py
127 lines (107 loc) · 4.88 KB
/
mirror_formulae.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
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 :
-------------------
| 1/f = 1/v + 1/u |
-------------------
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 two-dimensional 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 small-angle 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.in/articles/mirror-formula-derivation)
(Sign Convention adapted from
https://www.toppr.com/ask/content/concept/sign-convention-for-mirrors-210189/)
"""
def focal_length(distance_of_object: float, distance_of_image: float) -> float:
"""
>>> 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.
"""
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:
"""
>>> 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.
"""
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:
"""
>>> 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.
"""
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