From 76c4a443d921b229ee7ac53c1dbd7947b93c328f Mon Sep 17 00:00:00 2001 From: sanjuxvictus Date: Mon, 9 Oct 2023 21:07:30 +0530 Subject: [PATCH 1/4] Added Lens formulae to the Physics repository --- physics/lens_formulae.py | 133 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 physics/lens_formulae.py diff --git a/physics/lens_formulae.py b/physics/lens_formulae.py new file mode 100644 index 000000000000..b4d358e3f7ed --- /dev/null +++ b/physics/lens_formulae.py @@ -0,0 +1,133 @@ +""" + This module has functions which calculate focal length of lens, distance of + image from the lens and + distance of object from the lens. + The above is calculated uding the lens formula. + + In optics, the relationship between the distance of the image (v), + the distance of the object (u), and + the focal length (f) of the lens is given by the formula known as the Lens formula. + The Lens formula is applicable for convex as well as concave lenses. The formula + is given as follows: + + ------------------- + | 1/f = 1/v + 1/u | + ------------------- + + Where, + f = focal length of the lens in meters. + v = distance of the image from the lens in meters. + u = distance of the object from the lens in meters. + + To make our calculations easy few assumptions are made while deriving the formula + which are important to keep in mind before solving this equation. + The assumptions are as follows: + 1.The object O is a point object lying somewhere on the principle axis. + 2.The lens is thin. + 3.The aperture of the lens taken must be small. + 4.The angles of incidence and angle of refraction should be small. + + Sign convention is a set of rules to set signs for image distance, object distance, + focal length, etc + for mathematical analysis of image formation. According to it: + 1.Object is always placed to the left of lens. + 2.All distances are measured from the optical centre of the mirror. + 3.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. + 4.Distances measured along y-axis above the principal axis are positive and + that measured along y-axis below the principal + axis are negative. + + Note: Sign convention can be reversed and will still give the correct results. + + (Reference for Sign convention + https://www.toppr.com/ask/content/concept/sign-convention-for-lenses-210246/) + + (Reference for assumptions + https://testbook.com/physics/derivation-of-lens-maker-formula#:~:text=Assumptions%20of%20Lens%20Maker%27s%20Formula&text=The%20object%20O%20is%20a,of%20refraction%20should%20be%20small.) + + +""" + + +def focal_length_of_lens( + object_distance_from_lens: float, image_distance_from_lens: float +): + """ + Doctests: + >>> from math import isclose + >>> isclose(focal_length_of_lens(10,4), 6.666666666666667) + True + >>> from math import isclose + >>> isclose(focal_length_of_lens(2.7,5.8), -5.0516129032258075) + True + >>> focal_length_of_lens(0, 20) # doctest: +NORMALIZE_WHITESPACE + Traceback (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + + if object_distance_from_lens == 0 or image_distance_from_lens == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + focal_length = 1 / ( + (1 / image_distance_from_lens) - (1 / object_distance_from_lens) + ) + return focal_length + + +def object_distance(focal_length_of_lens: float, image_distance_from_lens: float): + """ + Doctests: + >>> from math import isclose + >>> isclose(object_distance(10,40), -13.333333333333332) + True + + >>> from math import isclose + >>> isclose(object_distance(6.2,1.5), 1.9787234042553192) + True + + >>> object_distance(0, 20) # doctest: +NORMALIZE_WHITESPACE + Traceback (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + + if image_distance_from_lens == 0 or focal_length_of_lens == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + + object_distance = 1 / ((1 / image_distance_from_lens) - (1 / focal_length_of_lens)) + return object_distance + + +def image_distance(focal_length_of_lens: float, object_distance_from_lens: float): + """ + 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 (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + if object_distance_from_lens == 0 or focal_length_of_lens == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + image_distance = 1 / ((1 / object_distance_from_lens) + (1 / focal_length_of_lens)) + return image_distance + + +print(focal_length_of_lens(50, 40)) From 80dc26f2fe05be0cd93c95d3542ef386f64465af Mon Sep 17 00:00:00 2001 From: sanjuxvictus Date: Tue, 10 Oct 2023 08:14:22 +0530 Subject: [PATCH 2/4] Resolved the commented issues --- physics/lens_formulae.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/physics/lens_formulae.py b/physics/lens_formulae.py index b4d358e3f7ed..03960d9a515c 100644 --- a/physics/lens_formulae.py +++ b/physics/lens_formulae.py @@ -53,7 +53,7 @@ def focal_length_of_lens( object_distance_from_lens: float, image_distance_from_lens: float -): +) -> float: """ Doctests: >>> from math import isclose @@ -79,7 +79,7 @@ def focal_length_of_lens( return focal_length -def object_distance(focal_length_of_lens: float, image_distance_from_lens: float): +def object_distance(focal_length_of_lens: float, image_distance_from_lens: float) -> float: """ Doctests: >>> from math import isclose @@ -106,7 +106,7 @@ def object_distance(focal_length_of_lens: float, image_distance_from_lens: float return object_distance -def image_distance(focal_length_of_lens: float, object_distance_from_lens: float): +def image_distance(focal_length_of_lens: float, object_distance_from_lens: float) -> float: """ Doctests: >>> from math import isclose @@ -128,6 +128,3 @@ def image_distance(focal_length_of_lens: float, object_distance_from_lens: float ) image_distance = 1 / ((1 / object_distance_from_lens) + (1 / focal_length_of_lens)) return image_distance - - -print(focal_length_of_lens(50, 40)) From 05d0220daaf463ae3ece2f8f6099e88877c60209 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 02:51:14 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/lens_formulae.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/physics/lens_formulae.py b/physics/lens_formulae.py index 03960d9a515c..093e4d7cd83b 100644 --- a/physics/lens_formulae.py +++ b/physics/lens_formulae.py @@ -79,7 +79,9 @@ def focal_length_of_lens( return focal_length -def object_distance(focal_length_of_lens: float, image_distance_from_lens: float) -> float: +def object_distance( + focal_length_of_lens: float, image_distance_from_lens: float +) -> float: """ Doctests: >>> from math import isclose @@ -106,7 +108,9 @@ def object_distance(focal_length_of_lens: float, image_distance_from_lens: float return object_distance -def image_distance(focal_length_of_lens: float, object_distance_from_lens: float) -> float: +def image_distance( + focal_length_of_lens: float, object_distance_from_lens: float +) -> float: """ Doctests: >>> from math import isclose From 9ee7ebe29187687f2534dc4d90d27d0fa1c3152f Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Thu, 26 Oct 2023 03:53:57 -0400 Subject: [PATCH 4/4] Update lens_formulae.py --- physics/lens_formulae.py | 95 +++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/physics/lens_formulae.py b/physics/lens_formulae.py index 093e4d7cd83b..162f3a8f3b29 100644 --- a/physics/lens_formulae.py +++ b/physics/lens_formulae.py @@ -1,53 +1,50 @@ """ - This module has functions which calculate focal length of lens, distance of - image from the lens and - distance of object from the lens. - The above is calculated uding the lens formula. - - In optics, the relationship between the distance of the image (v), - the distance of the object (u), and - the focal length (f) of the lens is given by the formula known as the Lens formula. - The Lens formula is applicable for convex as well as concave lenses. The formula - is given as follows: - - ------------------- - | 1/f = 1/v + 1/u | - ------------------- - - Where, - f = focal length of the lens in meters. - v = distance of the image from the lens in meters. - u = distance of the object from the lens in meters. - - To make our calculations easy few assumptions are made while deriving the formula - which are important to keep in mind before solving this equation. - The assumptions are as follows: - 1.The object O is a point object lying somewhere on the principle axis. - 2.The lens is thin. - 3.The aperture of the lens taken must be small. - 4.The angles of incidence and angle of refraction should be small. - - Sign convention is a set of rules to set signs for image distance, object distance, - focal length, etc - for mathematical analysis of image formation. According to it: - 1.Object is always placed to the left of lens. - 2.All distances are measured from the optical centre of the mirror. - 3.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. - 4.Distances measured along y-axis above the principal axis are positive and - that measured along y-axis below the principal - axis are negative. - - Note: Sign convention can be reversed and will still give the correct results. - - (Reference for Sign convention - https://www.toppr.com/ask/content/concept/sign-convention-for-lenses-210246/) - - (Reference for assumptions - https://testbook.com/physics/derivation-of-lens-maker-formula#:~:text=Assumptions%20of%20Lens%20Maker%27s%20Formula&text=The%20object%20O%20is%20a,of%20refraction%20should%20be%20small.) - - +This module has functions which calculate focal length of lens, distance of +image from the lens and distance of object from the lens. +The above is calculated using the lens formula. + +In optics, the relationship between the distance of the image (v), +the distance of the object (u), and +the focal length (f) of the lens is given by the formula known as the Lens formula. +The Lens formula is applicable for convex as well as concave lenses. The formula +is given as follows: + +------------------- +| 1/f = 1/v + 1/u | +------------------- + +Where + f = focal length of the lens in meters. + v = distance of the image from the lens in meters. + u = distance of the object from the lens in meters. + +To make our calculations easy few assumptions are made while deriving the formula +which are important to keep in mind before solving this equation. +The assumptions are as follows: + 1. The object O is a point object lying somewhere on the principle axis. + 2. The lens is thin. + 3. The aperture of the lens taken must be small. + 4. The angles of incidence and angle of refraction should be small. + +Sign convention is a set of rules to set signs for image distance, object distance, +focal length, etc +for mathematical analysis of image formation. According to it: + 1. Object is always placed to the left of lens. + 2. All distances are measured from the optical centre of the mirror. + 3. 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. + 4. Distances measured along y-axis above the principal axis are positive and + that measured along y-axis below the principal + axis are negative. + +Note: Sign convention can be reversed and will still give the correct results. + +Reference for Sign convention: +https://www.toppr.com/ask/content/concept/sign-convention-for-lenses-210246/ + +Reference for assumptions: +https://testbook.com/physics/derivation-of-lens-maker-formula """