Skip to content

Added Mirror Formulae Equation #9717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions physics/mirror_formulae.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

"""


from math import isclose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this import into the doctest so that the linter does not get confused.

def focal_length(distance_of_object: float, distance_of_image: float) -> float:
"""
>>> focal_length(10, 20)
6.666666666666667
>>> focal_length(9.5, 6.7)
3.929012346
>>> isclose(focal_length(10, 20), 6.666666666666667)
True
>>> isclose(focal_length(9.5, 6.7), 3.929012346)
True
>>> focal_length(0, 20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> focal_length(0, 20)  # doctest: +NORMALIZE_WHITESPACE

Traceback (most recent call last):
...
Expand All @@ -81,10 +81,10 @@ def focal_length(distance_of_object: float, distance_of_image: float) -> float:

def object_distance(focal_length: float, distance_of_image: float) -> float:
"""
>>> object_distance(30, 20)
-60
>>> object_distance(10.5, 11.7)
102.375
>>> isclose(object_distance(30, 20), -60.0)
True
>>> isclose(object_distance(10.5, 11.7), 102.375)
True
Copy link
Member

@cclauss cclauss Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we need is_close() here. Let’s only use it where we need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the doctests locally, there were issues when used without the isclose, should i still remove them or leave it as it is ?
image

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. We need is_close()

Copy link
Contributor Author

@vipinkarthic vipinkarthic Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything else I should add/change ?, or just have to wait till PR is merged ?

>>> object_distance(90, 0)
Copy link
Member

@cclauss cclauss Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# doctest: +NORMALIZE_WHITESPACE

Traceback (most recent call last):
...
Expand All @@ -100,12 +100,12 @@ def object_distance(focal_length: float, distance_of_image: float) -> float:
return object_distance


def image_distance(distance_of_object: float, focal_length: float) -> float:
def image_distance(focal_length: float, distance_of_object: float) -> float:
"""
>>> image_distance(10, 40)
13.33333333
>>> image_distance(1.5, 6.7)
1.932692308
>>> isclose(image_distance(10, 40), 13.33333333)
True
>>> isclose(image_distance(1.5, 6.7), 1.932692308)
True
>>> image_distance(0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# doctest: +NORMALIZE_WHITESPACE

Traceback (most recent call last):
...
Expand All @@ -117,5 +117,5 @@ def image_distance(distance_of_object: float, focal_length: float) -> float:
raise ValueError(
"Invalid inputs. Enter non zero values with respect to the sign convention."
)
image_distance = 1 / ((1 / focal_length) + (1 / distance_of_object))
image_distance = 1 / ((1 / focal_length) - (1 / distance_of_object))
return image_distance