generated from jupyterlite/demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/tBuLi/teahouse
- Loading branch information
Showing
2 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,286 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "bc700e90-af8f-446e-a3e2-a5623567113e", | ||
"metadata": {}, | ||
"source": [ | ||
"# Thin Lens\n", | ||
"\n", | ||
"This notebook shows the power of dimension agnostic thinking, by using the thin lens example first presented by Steven De Keninck in his [SIBGRAPI2021 talk](https://www.youtube.com/watch?v=2DgxeizE3E8). (Highly recommended viewing!)\n", | ||
"The code below is agnostic to the dimension of space as well as to the dimension of the object being imaged and the dimension of the properties of the lens." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "4bca94dc-d8d9-40bf-99cf-563387a08807", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Note: you may need to restart the kernel to use updated packages.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%pip install -q kingdon anywidget==0.9.9" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "2e501c13-9a4f-45f5-8d46-d2e824be9bfe", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from kingdon import Algebra\n", | ||
"\n", | ||
"clrs = [0xff9900, 0xfed290, 0x009977, 0x000000]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ce86a33b-3c8f-4543-ae49-e9a5b06ebe14", | ||
"metadata": {}, | ||
"source": [ | ||
"This code was written to be dimension agnostic: try changing to $d=3$ and rerun the notebook!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "e65f0c8f-900b-4b51-bc92-91f5ca1550ee", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"d = 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "ee8df3eb-90c8-4574-8c62-f52876568ecf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"alg = Algebra(d, 0, 1, graded=True)\n", | ||
"globals().update(alg.blades)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c81d2934-e455-455e-ae70-967bad4345d3", | ||
"metadata": {}, | ||
"source": [ | ||
"Immutable properties of the lens:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "9581e782-5c36-4dfc-98be-02730fb12072", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"lens = e1\n", | ||
"center_point = e0.dual() " | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "aa24a8eb-4129-4834-8a3f-30d20965c2d7", | ||
"metadata": {}, | ||
"source": [ | ||
"A thin lens also has a focal point and a center point. This is not true for a cylindrical lens; see the next cell." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "b895a022-e588-4497-9988-4a6f40c536c5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"focal = (e0 - 0.8*e1).dual() # Focal point of the lens\n", | ||
"center = e0.dual() # Center point of the lens" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7de46a6c-169e-492c-849c-94df36db9d7a", | ||
"metadata": {}, | ||
"source": [ | ||
"In order to switch the lens to a cylindrical lens, uncomment the lines below. This will turn the focal point and optical center of the lens into lines instead of points, and has the result that the lens now maps points to lines." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "98404b8f-8649-4732-9f54-60db59521dee", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# focal = focal | e3\n", | ||
"# center = center | e3" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5f43a813-bc2a-4737-80eb-c4b3eef58b0e", | ||
"metadata": {}, | ||
"source": [ | ||
"The object to be imaged. By default, this is a point." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "fd7c9afb-16ae-49b1-a498-95d4ea833e3e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"world = (e0 - 2*e1 - e2).dual()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d7a23ddc-b4be-4013-8ac4-5df22206e924", | ||
"metadata": {}, | ||
"source": [ | ||
"Alternativelly we can switch the input from a point to a line. To do so, uncomment the code below to turn the object into a line." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "ff7f5a33-d88d-4380-99d7-d649ef1b3661", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# world = world | e3" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "29ab6083-f8e1-4e94-8e8f-c53854973d05", | ||
"metadata": {}, | ||
"source": [ | ||
"Now all we need to find the image of the object through our lens is a ruler to draw some straight lines/planes! In essence, this makes the light ray trough the center of the lens, and intersects it with the light ray that travels through the focal point." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "36d8b3ac-88b4-41e0-8fbc-7aad067029cf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"wf = lambda: world & focal\n", | ||
"wc = lambda: world & center\n", | ||
"wfl = lambda: wf ^ lens # world on lens through focal\n", | ||
"wfl_dot_l = lambda: wfl | (center_point & wfl)\n", | ||
"img = lambda: alg.op(wfl_dot_l, wc).normalized()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "79daf7b0-401f-4201-9416-dc6fb8185610", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "4f88a5ce3f58471d9f8637d44d4d7595", | ||
"version_major": 2, | ||
"version_minor": 1 | ||
}, | ||
"text/plain": [ | ||
"GraphWidget(cayley=[['1', 'e0', 'e1', 'e2', 'e01', 'e02', 'e12', 'e012'], ['e0', '0', 'e01', 'e02', '0', '0', …" | ||
] | ||
}, | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"axis = lens | center_point # Optical axis of the line.\n", | ||
"\n", | ||
"def lens_graph_func():\n", | ||
" return [\n", | ||
" '<G stroke-opacity=\"0.5\">',\n", | ||
" axis, \n", | ||
" '</G>',\n", | ||
" clrs[2],\n", | ||
" world,\n", | ||
" clrs[0],\n", | ||
" center,\n", | ||
" focal, 'f',\n", | ||
" lens,\n", | ||
" '<G stroke-dasharray=\"0.1 0.1\" fill-opacity=\"0.4\">', clrs[1],\n", | ||
" wf,\n", | ||
" wc,\n", | ||
" wfl,\n", | ||
" lens | wfl,\n", | ||
" '</G>',\n", | ||
" '<G fill-opacity=\"0.2\">', clrs[1],\n", | ||
" [world, img, wfl],\n", | ||
" '</G>',\n", | ||
" clrs[3],\n", | ||
" img,\n", | ||
" ]\n", | ||
"\n", | ||
"alg.graph(\n", | ||
" lens_graph_func,\n", | ||
" lineWidth=4,\n", | ||
" pointRadius=2.5,\n", | ||
" fontSize=3,\n", | ||
" animate=True\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1902da41-ef1a-4ea5-843d-001dff341d7b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "82f88290-c21b-4316-a20d-308a598d1606", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.14" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters