Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
LMesaric committed Dec 19, 2018
1 parent bc2a97f commit 36e7573
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Photon Reflection #

Photon starts moving to the right from point `(0.50, 0.26)` in a grid lattice with a circular mirror in each point (`R=1/3`) - see [Visualization](https://github.com/LMesaric/PhotonReflection#visualization).
The speed of a photon is `1 point per second`. Where will the photon be located after `20 seconds`?
Photon starts moving to the right from point `(0.50, 0.26)` in a grid lattice with a circular mirror
in each point (`R = 1/3`) - see [Visualization](https://github.com/LMesaric/PhotonReflection#visualization).
The speed of the photon is `1 point per second`. Where will the photon be located after `t = 20 seconds`?

Solving this problem comes down to calculating the reflected line after interaction with the circle. All calculations must be done with very high precision.
Solving this problem comes down to calculating the reflected line after interaction with the circle.
All calculations must be done with very high precision - see
[Result dependency on precision](https://github.com/LMesaric/PhotonReflection#result-dependency-on-precision).

Algorithm used in this project does **not** use any trigonometric functions nor angles between lines.
The only _problematic_ part is calculating the square root, but that can easily be done in arbitrary precision.

## Photon reflections and final result ##
## Points of reflection and final result ##

Calculating with `100` significant digits, these are the points of reflection (except for 1<sup>st</sup> and 18<sup>th</sup>) rounded to `6` decimal places.
These are the points of reflection (impact), except for 1<sup>st</sup> and 18<sup>th</sup> point,
rounded to `6` decimal places. All decimal places are correct.

1. (+0.500000, +0.260000) - START
2. (+0.791407, +0.260000)
Expand Down Expand Up @@ -37,9 +43,14 @@ Calculating with `100` significant digits, these are the points of reflection (e

## Result dependency on precision ##

Final points calculated with different values of `N` are listed below. `N` is the number of significant digits used in all calculations.
Final points calculated with different values of `N` are listed below.
`N` is the number of significant digits used in all calculations.

It is important to notice that a `double` variable can store up to `15` stable decimal places, meaning that for values in range `<-100, 100>` it can store only `17` significant digits. That is the exact `N` at which a large computation error occurs. For this kind of calculations, one must use data types capable of storing numbers in very high precision, such as `BigDecimal` used in this project.
It is important to notice that a `double` variable can store up to `15` stable decimal places,
meaning that for values in range `<-100, 100>` it can store only `17` significant digits.
That is the exact `N` at which a large computation error occurs.
For this kind of calculations, one must use data types capable of storing numbers in very high precision.
_Java_'s `BigDecimal` type was used in this project.

N = 50000 => (+4.094557, -0.360327) - correct result
N = 24 => (+4.094557, -0.360327) - correct result
Expand All @@ -54,10 +65,25 @@ It is important to notice that a `double` variable can store up to `15` stable d
N = 15 => (+6.551874, +1.408657)
N = 14 => (+5.776366, -4.158442)

A small error in locating the impact point will make an error in the equation of the reflected line,
which will propagate to the next collision with a lever arm of the free path. Even with exact mathematical equations,
numerical errors will occur due to limited calculation precision. These errors will soon accumulate resulting in
critical errors such as completely missing a mirror which should have been hit.
Using symbolic calculations might seem like a good solution at first, but after just a few reflections
the expressions become incredibly complex and calculations are slowed down. Evaluating the final expression on its own
might result in large errors due to possible numerical instability.


## Visualization ##

Image below illustrates the entire problem and solution. Each of the reflection points is labeled with a number, from `1` to `18`. Connect the dots to get the photon's trajectory.
Image below illustrates the entire problem and solution for `t=20s`. Each of the reflection points is
labeled with a number, from `1` to `18`. Connecting the dots in order will give you the photon's trajectory.

![Desmos graph](https://raw.githubusercontent.com/LMesaric/PhotonReflection/master/images/PhotonReflection.png)

## Increasing the time frame ##

Let us increase the time frame from `t=20s` to `t=200s`, keeping all other parameters the same.
At that exact moment the photon will be positioned over point `(-15.454298, -7.616898)`.
This result will be consistently achieved for `N=140` and higher. It is quite obvious that using double precision
will produce completely unpredictable outcomes.

0 comments on commit 36e7573

Please sign in to comment.