|
| 1 | +""" |
| 2 | +This module contains the functions to calculate the focal length, object distance |
| 3 | +and image distance of a mirror. |
| 4 | +
|
| 5 | +The mirror formula is an equation that relates the object distance (u), |
| 6 | +image distance (v), and focal length (f) of a spherical mirror. |
| 7 | +It is commonly used in optics to determine the position and characteristics |
| 8 | +of an image formed by a mirror. It is expressed using the formulae : |
| 9 | +
|
| 10 | +------------------- |
| 11 | +| 1/f = 1/v + 1/u | |
| 12 | +------------------- |
| 13 | +
|
| 14 | +Where, |
| 15 | +f = Focal length of the spherical mirror (metre) |
| 16 | +v = Image distance from the mirror (metre) |
| 17 | +u = Object distance from the mirror (metre) |
| 18 | +
|
| 19 | +
|
| 20 | +The signs of the distances are taken with respect to the sign convention. |
| 21 | +The sign convention is as follows: |
| 22 | + 1) Object is always placed to the left of mirror |
| 23 | + 2) Distances measured in the direction of the incident ray are positive |
| 24 | + and the distances measured in the direction opposite to that of the incident |
| 25 | + rays are negative. |
| 26 | + 3) All distances are measured from the pole of the mirror. |
| 27 | +
|
| 28 | +
|
| 29 | +There are a few assumptions that are made while using the mirror formulae. |
| 30 | +They are as follows: |
| 31 | + 1) Thin Mirror: The mirror is assumed to be thin, meaning its thickness is |
| 32 | + negligible compared to its radius of curvature. This assumption allows |
| 33 | + us to treat the mirror as a two-dimensional surface. |
| 34 | + 2) Spherical Mirror: The mirror is assumed to have a spherical shape. While this |
| 35 | + assumption may not hold exactly for all mirrors, it is a reasonable approximation |
| 36 | + for most practical purposes. |
| 37 | + 3) Small Angles: The angles involved in the derivation are assumed to be small. |
| 38 | + This assumption allows us to use the small-angle approximation, where the tangent |
| 39 | + of a small angle is approximately equal to the angle itself. It simplifies the |
| 40 | + calculations and makes the derivation more manageable. |
| 41 | + 4) Paraxial Rays: The mirror formula is derived using paraxial rays, which are |
| 42 | + rays that are close to the principal axis and make small angles with it. This |
| 43 | + assumption ensures that the rays are close enough to the principal axis, making the |
| 44 | + calculations more accurate. |
| 45 | + 5) Reflection and Refraction Laws: The derivation assumes that the laws of |
| 46 | + reflection and refraction hold. |
| 47 | + These laws state that the angle of incidence is equal to the angle of reflection |
| 48 | + for reflection, and the incident and refracted rays lie in the same plane and |
| 49 | + obey Snell's law for refraction. |
| 50 | +
|
| 51 | +(Description and Assumptions adapted from |
| 52 | +https://www.collegesearch.in/articles/mirror-formula-derivation) |
| 53 | +
|
| 54 | +(Sign Convention adapted from |
| 55 | +https://www.toppr.com/ask/content/concept/sign-convention-for-mirrors-210189/) |
| 56 | +
|
| 57 | +
|
| 58 | +""" |
| 59 | + |
| 60 | + |
| 61 | +def 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) |
| 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 | + |
| 84 | +def object_distance(focal_length: float, distance_of_image: float) -> float: |
| 85 | + """ |
| 86 | + >>> from math import isclose |
| 87 | + >>> isclose(object_distance(30, 20), -60.0) |
| 88 | + True |
| 89 | + >>> from math import isclose |
| 90 | + >>> isclose(object_distance(10.5, 11.7), 102.375) |
| 91 | + True |
| 92 | + >>> object_distance(90, 0) |
| 93 | + Traceback (most recent call last): |
| 94 | + ... |
| 95 | + ValueError: Invalid inputs. Enter non zero values with respect |
| 96 | + to the sign convention. |
| 97 | + """ |
| 98 | + |
| 99 | + if distance_of_image == 0 or focal_length == 0: |
| 100 | + raise ValueError( |
| 101 | + "Invalid inputs. Enter non zero values with respect to the sign convention." |
| 102 | + ) |
| 103 | + object_distance = 1 / ((1 / focal_length) - (1 / distance_of_image)) |
| 104 | + return object_distance |
| 105 | + |
| 106 | + |
| 107 | +def 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) |
| 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 |
0 commit comments