homework 7, version 1
Submission by: Jazzy Doe (jazz@mit.edu)
Oopsie! You need to update Pluto to the latest version
Close Pluto, go to the REPL, and type:
julia> import Pkg
julia> Pkg.update("Pluto")
Homework 7: Raytracing in 2D
18.S191
, fall 2020
This notebook contains built-in, live answer checks! In some exercises you will see a coloured box, which runs a test case on your code, and provides feedback based on the result. Simply edit the code, run it, and the check runs again.
For MIT students: there will also be some additional (secret) test cases that will be run as part of the grading process, and we will look at your notebook and write comments.
Feel free to ask questions!
"Jazzy Doe"
"jazz"
Let's create a package environment:
Activating new project at `/tmp/jl_KQihrG` Updating registry at `~/.julia/registries/General.toml` Resolving package versions... Updating `/tmp/jl_KQihrG/Project.toml` [91a5bcdd] + Plots v1.40.10 [7f904dfe] + PlutoUI v0.6.11 Updating `/tmp/jl_KQihrG/Manifest.toml` [66dad0bd] + AliasTables v1.1.3 [d1d4a3ce] + BitFlags v0.1.9 [d360d2e6] + ChainRulesCore v1.25.1 [9e997f8a] + ChangesOfVariables v0.1.9 [944b1d66] + CodecZlib v0.7.8 [35d6a980] + ColorSchemes v3.29.0 [3da002f7] + ColorTypes v0.12.0 [c3611d14] + ColorVectorSpace v0.11.0 [5ae59095] + Colors v0.13.0 [34da2185] + Compat v4.16.0 [f0e56b4a] + ConcurrentUtilities v2.5.0 [187b0558] + ConstructionBase v1.5.8 [d38c429a] + Contour v0.6.3 [9a962f9c] + DataAPI v1.16.0 [864edb3b] + DataStructures v0.18.20 [ffbed154] + DocStringExtensions v0.9.3 [460bff9d] + ExceptionUnwrapping v0.1.11 [c87230d0] + FFMPEG v0.4.2 [53c48c17] + FixedPointNumbers v0.8.5 [1fa38f19] + Format v1.3.7 [28b8d3ca] + GR v0.73.6 [42e2da0e] + Grisu v1.0.2 [cd3eb016] + HTTP v1.10.15 [3587e190] + InverseFunctions v0.1.17 [92d709cd] + IrrationalConstants v0.2.4 [1019f520] + JLFzf v0.1.9 [692b3bcd] + JLLWrappers v1.7.0 [682c06a0] + JSON v0.21.4 [b964fa9f] + LaTeXStrings v1.4.0 [23fbe1c1] + Latexify v0.16.6 [2ab3a3ac] + LogExpFunctions v0.3.28 [e6f89c97] + LoggingExtras v1.1.0 [1914dd2f] + MacroTools v0.5.15 [739be429] + MbedTLS v1.1.9 [442fdcdd] + Measures v0.3.2 [e1d29d7a] + Missings v1.2.0 [77ba4419] + NaNMath v1.0.3 [4d8831e6] + OpenSSL v1.4.3 [bac558e1] + OrderedCollections v1.8.0 [69de0a69] + Parsers v2.8.1 [b98c9c47] + Pipe v1.3.0 [ccf2f8ad] + PlotThemes v3.3.0 [995b91a9] + PlotUtils v1.4.3 [91a5bcdd] + Plots v1.40.10 [7f904dfe] + PlutoUI v0.6.11 [aea7be01] + PrecompileTools v1.2.1 [21216c6a] + Preferences v1.4.3 [43287f4e] + PtrArrays v1.3.0 [3cdcf5f2] + RecipesBase v1.3.4 [01d81517] + RecipesPipeline v0.6.12 [189a3867] + Reexport v1.2.2 [05181044] + RelocatableFolders v1.0.1 [ae029012] + Requires v1.3.1 [6c6a2e73] + Scratch v1.2.1 [992d4aef] + Showoff v1.0.3 [777ac1f9] + SimpleBufferStream v1.2.0 [a2af1166] + SortingAlgorithms v1.2.1 [860ef19b] + StableRNGs v1.0.2 [82ae8749] + StatsAPI v1.7.0 [2913bbd2] + StatsBase v0.34.4 [fd094767] + Suppressor v0.2.8 [62fd8b95] + TensorCore v0.1.1 [3bb67fe8] + TranscodingStreams v0.11.3 [5c2747f8] + URIs v1.5.1 [1cfade01] + UnicodeFun v0.4.1 [1986cc42] + Unitful v1.22.0 [45397f5d] + UnitfulLatexify v1.6.4 [41fe7b60] + Unzip v0.2.0 [6e34b625] + Bzip2_jll v1.0.9+0 [83423d85] + Cairo_jll v1.18.2+1 [ee1fde0b] + Dbus_jll v1.14.10+0 [2702e6a9] + EpollShim_jll v0.0.20230411+1 [2e619515] + Expat_jll v2.6.5+0 [b22a6f82] + FFMPEG_jll v4.4.4+1 [a3f928ae] + Fontconfig_jll v2.15.0+0 [d7e528f0] + FreeType2_jll v2.13.3+1 [559328eb] + FriBidi_jll v1.0.16+0 [0656b61e] + GLFW_jll v3.4.0+2 [d2c73de3] + GR_jll v0.73.6+0 [78b55507] + Gettext_jll v0.21.0+0 [7746bdde] + Glib_jll v2.82.4+0 [3b182d85] + Graphite2_jll v1.3.14+1 [2e76f6c2] + HarfBuzz_jll v8.5.0+0 [aacddb02] + JpegTurbo_jll v3.1.1+0 [c1c5ebd0] + LAME_jll v3.100.2+0 [88015f11] + LERC_jll v3.0.0+1 [1d63c593] + LLVMOpenMP_jll v18.1.7+0 [dd4b983a] + LZO_jll v2.10.3+0 [e9f186c6] + Libffi_jll v3.2.2+2 [d4300ac3] + Libgcrypt_jll v1.11.0+0 [7e76a0d4] + Libglvnd_jll v1.7.0+0 [7add5ba3] + Libgpg_error_jll v1.51.1+0 [94ce4f54] + Libiconv_jll v1.18.0+0 [4b2f31a3] + Libmount_jll v2.40.3+0 [89763e89] + Libtiff_jll v4.5.1+1 [38a345b3] + Libuuid_jll v2.40.3+0 [e7412a2a] + Ogg_jll v1.3.5+1 [458c3c95] + OpenSSL_jll v3.0.16+0 [91d4177d] + Opus_jll v1.3.3+0 [36c8627f] + Pango_jll v1.56.1+0 [30392449] + Pixman_jll v0.43.4+0 [c0090381] + Qt6Base_jll v6.7.1+1 [a44049a8] + Vulkan_Loader_jll v1.3.243+0 [a2964d1f] + Wayland_jll v1.21.0+2 [2381bf8a] + Wayland_protocols_jll v1.36.0+0 [02c8fc9c] + XML2_jll v2.13.6+1 [aed1982a] + XSLT_jll v1.1.42+0 [ffd25f8a] + XZ_jll v5.6.4+1 [f67eecfb] + Xorg_libICE_jll v1.1.1+0 [c834827a] + Xorg_libSM_jll v1.2.4+0 [4f6342f7] + Xorg_libX11_jll v1.8.6+3 [0c0b7dd1] + Xorg_libXau_jll v1.0.12+0 [935fb764] + Xorg_libXcursor_jll v1.2.3+0 [a3789734] + Xorg_libXdmcp_jll v1.1.5+0 [1082639a] + Xorg_libXext_jll v1.3.6+3 [d091e8ba] + Xorg_libXfixes_jll v6.0.0+0 [a51aa0fd] + Xorg_libXi_jll v1.8.2+0 [d1454406] + Xorg_libXinerama_jll v1.1.5+0 [ec84b674] + Xorg_libXrandr_jll v1.5.4+0 [ea2f1a96] + Xorg_libXrender_jll v0.9.11+1 [14d82f49] + Xorg_libpthread_stubs_jll v0.1.2+0 [c7cfdc94] + Xorg_libxcb_jll v1.17.0+3 [cc61e674] + Xorg_libxkbfile_jll v1.1.2+1 [e920d4aa] + Xorg_xcb_util_cursor_jll v0.1.4+0 [12413925] + Xorg_xcb_util_image_jll v0.4.0+1 [2def613f] + Xorg_xcb_util_jll v0.4.0+1 [975044d2] + Xorg_xcb_util_keysyms_jll v0.4.0+1 [0d47668e] + Xorg_xcb_util_renderutil_jll v0.3.9+1 [c22f9ab0] + Xorg_xcb_util_wm_jll v0.4.1+1 [35661453] + Xorg_xkbcomp_jll v1.4.6+1 [33bec58e] + Xorg_xkeyboard_config_jll v2.39.0+0 [c5fb5394] + Xorg_xtrans_jll v1.5.1+0 [3161d3a3] + Zstd_jll v1.5.7+1 [35ca27e7] + eudev_jll v3.2.9+0 [214eeab7] + fzf_jll v0.56.3+0 [1a1c6b14] + gperf_jll v3.1.1+1 [a4ae2306] + libaom_jll v3.11.0+0 [0ac62f75] + libass_jll v0.15.2+0 [1183f4f0] + libdecor_jll v0.2.2+0 [2db6ffa8] + libevdev_jll v1.11.0+0 [f638f0a6] + libfdk_aac_jll v2.0.3+0 [36db933b] + libinput_jll v1.18.0+0 [b53b4c65] + libpng_jll v1.6.47+0 [f27f6e37] + libvorbis_jll v1.3.7+2 [009596ad] + mtdev_jll v1.1.6+0 [1270edf5] + x264_jll v2021.5.5+0 [dfaa095f] + x265_jll v3.5.0+0 [d8fb68d0] + xkbcommon_jll v1.4.1+2 [0dad84c5] + ArgTools [56f22d72] + Artifacts [2a0f44e3] + Base64 [ade2ca70] + Dates [8bb1440f] + DelimitedFiles [f43a241f] + Downloads [7b1f6079] + FileWatching [b77e0a4c] + InteractiveUtils [b27032c2] + LibCURL [76f85450] + LibGit2 [8f399da3] + Libdl [37e2e46d] + LinearAlgebra [56ddb016] + Logging [d6f4376e] + Markdown [a63ad114] + Mmap [ca575930] + NetworkOptions [44cfe95a] + Pkg [de0858da] + Printf [3fa0cd96] + REPL [9a3f8284] + Random [ea8e919c] + SHA [9e88b42a] + Serialization [6462fe0b] + Sockets [2f01184e] + SparseArrays [10745b16] + Statistics [fa267f1f] + TOML [a4e569a6] + Tar [8dfed614] + Test [cf7118a7] + UUIDs [4ec0a83e] + Unicode [e66e0078] + CompilerSupportLibraries_jll [deac9b47] + LibCURL_jll [29816b5a] + LibSSH2_jll [c8ffd9c3] + MbedTLS_jll [14a3606d] + MozillaCACerts_jll [4536629a] + OpenBLAS_jll [05823500] + OpenLibm_jll [efcefdf7] + PCRE2_jll [83775a58] + Zlib_jll [8e850b90] + libblastrampoline_jll [8e850ede] + nghttp2_jll [3f19e933] + p7zip_jll
Exercise 1: Walls
As discussed the lecture, event-driven simulations are the traditional method used for raytracing. Here, we look for any objects in our path and analytically determine how far away they are. From there, we take one big timestep all the way to the surface boundary, calculate refraction or reflection to see what direction we are moving in, and then seek out any other object we could potentially run into.
So let's start simple with determining when a ray of light could intersect with a wall.
Exercise 1.1 - what is a wall?
To start, let's create the concept of a wall. For our purposes, walls will be infinitely long, so we only need to create an object that has a position and a normal vector at that position:
8.0
-1.0
-0.948683
0.316228
plot_object! (generic function with 1 method)
plot_scene (generic function with 1 method)
In our simulations, we will enclose our scene in a box of four walls, to make sure that no rays can escape the scene. We have written this box (i.e. vector of walls) below, but we are still missing the roof.
10.0
0.0
-1.0
0.0
-10.0
0.0
1.0
0.0
0.0
-10.0
0.0
1.0
👉 Modify the definition of box_scene
to be a vector of 4 walls, instead of 3. The fourth wall should be positioned at [0,10]
, and point downwards.
Keep working on it!
The answer is not quite right.
In the next exercise, we will find the intersection of a ray of light and a wall. To represent light, we create a struct
called Photon
, holding the position and travel direction of a single particle of light. We also include the index of refraction of the medium it is currently traveling in, we will use this later.
-1.0
2.0
0.780869
-0.624695
1.0
plot_photon_arrow! (generic function with 2 methods)
Exercise 1.2 - how far is the wall?
We will write a function that finds the location where a photon hits the wall. Instead of moving the photon forward in small timesteps until we reach the wall, we will compute the intersection directly, making use of the fact that the wall is a geometrically simple object.
Our function will return one of two possible types: a Miss
or a Intersection
. We define these types below, and both definitions need some elaboration.
Miss
is a struct with no fields. It does not contain any information, except the fact that it is a Miss
. You create a new Miss
object like so:
Intersection
is a parametric type. The first field (object
) is of type T
, and T
is a subtype of Object
. Have a look at the definition above, and take note of how we write such statements in Julia syntax.
We also could have used Object
directly as the type for the field object
, but what's special about parametric types is that T
becomes "part of the type". Let's have a look at an example:
8.0
-1.0
-0.948683
0.316228
3.0
1.0
2.0
Intersection{Wall}
You see that Wall
is included in the type. This will be very useful later, when we want to do something different depending on the intersected object (wall, sphere, etc.) using multiple dispatch. We can write one method for ::Intersection{Sphere}
, and one for ::Intersection{Wall}
.
Wall geometry
So, how do we find the location where it hits the wall? Well, because our walls are infinitely long, we are essentially trying to find the point at which 2 lines intersect.
To do this, we can combine a few dot products: one to find how far away we are, and another to scale that distance. Mathematically, it would look like:
where
👉 Write a function intersection_distance
that implements this formula, and returns dot(a,b)
to compute the vector dot product
intersection_distance (generic function with 1 method)
Here we go!
Replace missing
with your answer.
Exercise 1.3 - hitting the wall
👉 Write a function intersection
that takes a photon
and a wall
, and returns either a Miss
or an Intersection
, based on the result of intersection_distance(photon, wall)
If Intersection
. We already have the intersected object, and we have
If Miss
.
Floating points
We are using floating points (Float64
) to store positions, distances, etc., which means that we need to account for small errors. Like in the lecture, we will not check for D > 0
, but D > ϵ
with ϵ = 1e-3
.
intersection (generic function with 1 method)
Here we go!
Replace missing
with your answer.
0.0
1.0
0.588501
-0.808496
1.0
missing
Exercise 1.4 - which wall?
We are now able to find the Intersection
of a single photon with a single wall (or detect a Miss
). Great! To make our simulation more interesting, we will combine multiple walls into a single scene.
3.0
0.0
0.447214
-0.894427
1.0
10.0
0.0
-1.0
0.0
-10.0
0.0
1.0
0.0
0.0
-10.0
0.0
1.0
8.0
-1.0
-0.948683
0.316228
When we shoot a photon at the scene, we compute the intersections between the photon and every object in the scene. Click on the vector below to see all elements:
missing
missing
missing
missing
There are two misses and three intersections. Just what we hoped!
So which of these five results should we use to determine what the photon does next? It should be the closest intersection.
Because we used two different types for hits and misses, we can express this in a charming way. We define what it means for one to be better than the other:
And we can now use all of Julia's built in functions to work with a vector of hit/miss results. For example, we can sort it:
missing
missing
missing
missing
And we can take the minimum:
missing
Note that we did not define the
sort
andminimum
methods ourselves! We only added methods forBase.isless
.
By taking the minimum, we have found our closest hit! Let's turn this into a function.
👉 Write a function closest_hit
that takes a photon
and a vector of objects. Calculate the vector of Intersection
s/Miss
es, and return the minimum
.
closest_hit (generic function with 1 method)
missing
type Missing has no field point
Here is what happened, the most recent locations are first:
Exercise 2: Mirrors
Now we're going to make a bold claim: All walls in this simulation are mirrors. This is just for simplicity so we don't need to worry about rays stopping at the boundaries.
We are already able to find the intersection of a light ray with a mirror, but we still need to tell our friendly computer what a reflection is.
Exercise 2.1 - reflect
For this one, we need to implement a reflection function. This one is way easier than refraction. All we need to do is find how much of the light is moving in the direction of the surface's normal and subtract that twice.
Where
reflect (generic function with 1 method)
👉 Verify that the function reflect
works by writing a simple test case:
Exercise 2.2 - step
Our event-driven simulation is a stepping method, but instead of taking small steps in time, we take large steps from one collision event to the next.
👉 Write a function interact
that takes a photon and a hit::Intersection{Wall}
and returns a new Photon
at the next step. The new photon is located at the hit point, its direction is reflected off the wall's normal and the photon.ior
is reused.
interact (generic function with 1 method)
Hint
Intersection
contains the intersected object, so you can retrieve the wall using hit.object
, and the normal using hit.object.normal
.
MethodError: no method matching interact(::Main.workspace#3.Photon, ::Missing)
Closest candidates are:
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Wall}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#2c6defd0-1ca1-11eb-17db-d5cb498f3265:1
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Sphere}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#427747d6-1ca1-11eb-28ae-ff50728c84fe:1
Here is what happened, the most recent locations are first:
Another cell defining test_new_photon contains errors.
For convenience, we define a function step_ray
that combines these two actions: it finds the closest hit and computes the interaction.
step_ray (generic function with 1 method)
Great! Next, we will repeat this action to trace the path of a photon.
Exercise 2.3 - accumulate
👉 Write a function trace
that takes an initial Photon
, a vector of Object
s and N
, the number of steps to make. Return a vector of Photon
s. Try to use accumulate
.
trace (generic function with 1 method)
MethodError: no method matching length(::Missing)
Closest candidates are:
length(::Union{Base.KeySet, Base.ValueIterator}) at /opt/hostedtoolcache/julia/1.7.3/x64/share/julia/base/abstractdict.jl:58
length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at /opt/hostedtoolcache/julia/1.7.3/x64/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:171
length(::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at ~/.julia/packages/DataStructures/95DJa/src/ordered_robin_dict.jl:86
...
Here is what happened, the most recent locations are first:
- length
(g::Base.Generator{Missing, var"#7#8"}) from generator.jl:50 - _similar_shape
(itr::Base.Generator{Missing, var"#7#8"}, #unused#::Base.HasLength) from array.jl:600 - collect
(itr::Base.Generator{Missing, var"#7#8"}) from array.jl:723 - from This cell: line 7
line = [philip.p, [r.p for r in path]...]
plot!(p, first.(line), last.(line), lw=5, color=:pink)
Recap
In Exercise 3 and 4, we will add a Sphere
type, and our scene will consist of Wall
s (mirrors) and Sphere
s (lenses). But before we move on, let's review what we have done so far.
Our main character is a Photon
, which bounces around a scene made up of Wall
s.
Using
intersection(photon, wall::Wall)
we can find either anIntersection
(containing thewall
, thedistance
and thepoint
) or aMiss
.Our scene is just a
Vector
or objects, and we compute the intersection between the photon and every object.By adding
Base.isless
methods we have told Julia how to compare hit/miss results, and we get the closest one usingminimum(all_intersections)
.We wrote a function
interact(photon, hit::Intersection{Wall})
that returns a new photon after interacting with a wall collision.
We repeat these four steps to trace a ray through the scene.
In the next two exercises we will reuse some of the functionality that we have already written, using multiple dispatch! For example, we add a method intersection(photon, sphere::Sphere)
, and steps 2 and 3 magically also work with spheres!
Exercise 3: Spheres
Now that we know how to bounce light around mirrors, we want to simulate a spherical lens to make things more interesting. Let's define a Sphere
.
plot_object! (generic function with 2 methods)
7.0
-6.0
2
1.5
Exercise 3.1
Just like with the Wall
, our first step is to be able to find the intersection point of a ray of light and a sphere.
This one is a bit more challenging than the intersction with the wall, in particular because there are 3 potential outcomes of a line interacting with a sphere:
No intersection
1 intersection
2 intersections
As shown below:

So we need a way of finding all of these.
To start, let's look at the intersection of a point and a sphere. So long as the relative distance between the photon and the sphere's center satisfies the sphere equation, we can be considered inside of the sphere. More specifically, we are inside the sphere if:
where the
Let's rewrite this in vector notation as:
where
Returning to the timestepping example from above, we know that our ray is moving forward with time such that
To solve this for
This can be solved with the good ol' fashioned quadratic equation:
where
If the quadratic equation returns no roots, there is no intersection. If it returns 1 root, the ray just barely hits the edge of the sphere. If it returns 2 roots, it goes right through!
The easiest way to check this is by looking at the discriminant
In the case that there are 2 roots, the second root corresponds to when the ray would interact with the far edge of the sphere if there were no refraction or reflection!; therefore, we only care about returning the closest point.
With all this said, we are ready to write some code.
👉 Write a new method intersection
that takes a Photon
and a Sphere
, and returns either a Miss
or an Intersection
, using the method described above. Go back to Exercise 1.3 where we defined the first method, and see how we adapt it to a sphere.
intersection (generic function with 2 methods)
missing
7.0
-6.0
2
1.5
7.0
-6.0
2
1.5
10.0
0.0
-1.0
0.0
-10.0
0.0
1.0
0.0
0.0
-10.0
0.0
1.0
👉 Change the definition of test_sphere
to test different situations:
Hit the circle
Miss the circle
Start inside the cricle (you should hit the exit boundary)
Exercise 4: Lenses
For this, we will start with refraction from the surface of water and then move on to a spherical lens.
So, how does refraction work? Well, every time light enters a new medium that is more dense than air, it will bend towards the normal to the surface, like so:

This can be described by Snell's law:
Here,
This means that we can find the angle of the new ray of light as
The problem is that
We also know that
Finally, we know that the new light direction should be the same as the old one, but shifted towards (or away) from the normal according to the new refractive index. In particular:
where
Now, we already know
and
Now, we can rewrite everything such that
The last step is to write this in code with a function that takes the light direction, the normal, and old and new indices of refraction:
refract (generic function with 1 method)
Now to move on to lenses. Like in lecture, we will focus exclusively on spherical lenses. Ultimately, there isn't a big difference between a lens and a spherical drop of water. It just has a slightly different refractive index and it's normal is defined slightly differently.
We need a helper functions to find the normal of the sphere's surface at any position. Remember that the normal will always be pointing perpendicularly from the surface of the sphere. This means that no matter what point you are at, the normal will just be a normalized vector of your current location minus the sphere's position:
sphere_normal_at (generic function with 1 method)
👉 Write a new method for interact
that takes a photon
and a hit
of type Intersection{Sphere}
, that implements refraction. It returns a new Photon
positioned at the hit point, with the refracted velocity and the new index of refraction.
Hint
You can use ray.ior == 1.0
to check whether this is a ray entering or leaving the sphere.
interact (generic function with 2 methods)
To test your code, modify the definition of test_lens_photon
and test_lens
below.
0.0
0.0
1.0
0.0
1.0
5.0
-1.5
3
1.5
MethodError: no method matching interact(::Main.workspace#3.Photon, ::Missing)
Closest candidates are:
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Wall}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#2c6defd0-1ca1-11eb-17db-d5cb498f3265:1
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Sphere}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#427747d6-1ca1-11eb-28ae-ff50728c84fe:1
Here is what happened, the most recent locations are first:
- step_ray
(photon::Main.workspace#3.Photon, objects::Vector{Main.workspace#3.Object}) from Other cell: line 4hit = closest_hit(photon, objects)
interact(photon, hit)
end
- Show more...
By defining a method for interact
that takes a sphere intersection, we are now able to use the machinery developed in Exercise 2 to simulate a scene with both lenses and mirrors. Let's try it out!
MethodError: no method matching interact(::Main.workspace#3.Photon, ::Missing)
Closest candidates are:
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Wall}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#2c6defd0-1ca1-11eb-17db-d5cb498f3265:1
interact(::Main.workspace#3.Photon, ::Main.workspace#3.Intersection{Main.workspace#3.Sphere}) at ~/work/disorganised-mess/disorganised-mess/hw7.jl#==#427747d6-1ca1-11eb-28ae-ff50728c84fe:1
Here is what happened, the most recent locations are first:
- step_ray
(photon::Main.workspace#3.Photon, objects::Vector{Main.workspace#3.Object}) from Other cell: line 4hit = closest_hit(photon, objects)
interact(photon, hit)
end
- Show more...
Spherical aberration
Now we can put it all together into an image of spherical aberration!
👉 Recreate the spherical aberration figure from the lecture (around the end of the video), and make the index of refraction interactive using a Slider
. Or make something else!
Exercise XX: Lecture transcript
(MIT students only) Please see the link for hw 7 transcript document on Canvas. We want each of you to correct about 500 lines, but don’t spend more than 20 minutes on it. See the the beginning of the document for more instructions.
👉 Please mention the name of the video(s) and the line ranges you edited:
Abstraction, lines 1-219; Array Basics, lines 1-137; Course Intro, lines 1-144 (for example)
Before you submit
Remember to fill in your name and Kerberos ID at the top of this notebook.
Function library
Just some helper functions used in the notebook.
hint (generic function with 1 method)
almost (generic function with 1 method)
still_missing (generic function with 2 methods)
keep_working (generic function with 2 methods)
Fantastic!
Splendid!
Great!
Yay ❤
Great! 🎉
Well done!
Keep it up!
Good job!
Awesome!
You got the right answer!
Let's move on to the next section.
correct (generic function with 2 methods)
not_defined (generic function with 1 method)
TODO_note (generic function with 1 method)