Function Repository Resource:

LensManipulate

Source Notebook

Generate a graphic in which the thin-lens parameters can be manipulated dynamically

Contributed by: Julián Laverde
Jason Martinez

ResourceFunction["LensManipulate"][]

returns a manipulable graphic of the ray diagram of a thin lens.

ResourceFunction["LensManipulate"][assoc]

returns a graphic with the corresponding parameters in the Association assoc.

Details and Options

The available thin lenses are biconvex and biconcave.
ResourceFunction["LensManipulate"] follows the sign convention for thin lenses from Hecht, Optics, Pearson, 2015:
Object distance (+) real object(-) virtual object
Focal length (+) converging lens(-) diverging lens
Image distance (+) real image(-) virtual image
Object size(+) erect object(-) inverted object
Image size(+) erect image(-) inverted image
Magnification (M)(+) erect image(-) inverted image
The linear magnification factor of the system is given by the equation , defined as the ratio of the size of the image compared to the size of the object.
ResourceFunction["LensManipulate"] uses the Gaussian lens formula to calculate the image distance si.
The arrow in the middle of the rays represents the direction of light and dotted lines the projection of the rays.
Real images and virtual images are represented by a thick-line arrow and a dotted-line arrow, respectively.
In ResourceFunction["LensManipulate"][assoc], the Association assoc can contain the following elements:
"Diameter"4lens (half) diameter
"ObjectSize"0.5object initial size
"FocalLength""Diameter"lens initial focal length
"ObjectDistance""FocalLength"object initial position
"ObjectDistance" can be a positive number or quantity of length.
"ObjectSize" can be a number or quantity of length in the range[-1,1].
"FocalLength" can be a positive or negative number or quantity of length.
Quantity inputs should have units of length. Results and values in sliders will be shown in the most common unit among the inputs.
ResourceFunction["LensManipulate"][] takes the options of Graphics and the following:
"RayColor"Automaticspecify the colors of the rays
"LensColor"Automaticspecify the color of the lens
"ArrowColor"Automaticspecify the colors of the object and image arrows
"ShowEquations"Trueset the equations in the graphics object
"ObjectDistanceRange"Automaticspecify the range of "ObjectDistance"
"ObjectSizeRange"Automaticspecify the range of "ObjectSize"
"FocalLengthRange"Automaticspecify the range of "FocalLength"
The copy values button copies the current values of "ObjectDistance", "FocalLength", "ImageDistance" and "Magnification" to the clipboard as an Association.

Examples

Basic Examples (2) 

Get a manipulable thin lens ray diagram:

In[1]:=
ResourceFunction["LensManipulate"][]
Out[1]=

Get the ray diagram for a set of specified initial values:

In[2]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> 10, "Diameter" -> 5, "ObjectDistance" -> 4, "ObjectSize" -> 0.4|>]
Out[2]=

Scope (2) 

Get the ray diagram for a negative thin lens:

In[3]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> -19, "ObjectDistance" -> 14, "Diameter" -> 10|>]
Out[3]=

Include inputs with quantities:

In[4]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> Quantity[1, "Meters"], "ObjectDistance" -> Quantity[5, "Meters"]|>]
Out[5]=

Options (7) 

LensManipulate takes the options of Graphics:

In[6]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> 10, "Diameter" -> 10|>, Axes -> True, ImageSize -> Large]
Out[6]=

ShowEquations (1) 

Set "ShowEquations" to False:

In[7]:=
ResourceFunction["LensManipulate"][<|"FocalLength" -> 10|>, "ShowEquations" -> False]
Out[7]=

RayColor (1) 

Change the color of the rays:

In[8]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> -11, "Diameter" -> 10|>, "RayColor" -> {Darker[Green], Blue, Orange}]
Out[8]=

ArrowColor (1) 

Change the color of the object and virtual arrows:

In[9]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> 6, "Diameter" -> 5|>, "ArrowColor" -> {Gray, Blue}]
Out[9]=

LensColor (1) 

Specify the color of the lens:

In[10]:=
ResourceFunction["LensManipulate"]["LensColor" -> {Blue}]
Out[10]=

ObjectDistanceRange (1) 

Specify the range of "ObjectDistance":

In[11]:=
ResourceFunction["LensManipulate"][<|"ObjectDistance" -> 18|>, "ObjectDistanceRange" -> {15, 20}]
Out[11]=

ObjectSizeRange (1) 

Specify the range of "ObjectSize":

In[12]:=
ResourceFunction["LensManipulate"]["ObjectSizeRange" -> {0.4, 0.6}]
Out[12]=

FocalLengthRange (1) 

Specify the range of "FocalLength":

In[13]:=
ResourceFunction[
 "LensManipulate"][<|"ObjectDistance" -> -5, "FocalLength" -> -8, "Diameter" -> 5|>, "FocalLengthRange" -> {-10, -5}]
Out[13]=

Neat Examples (1) 

Customize the style:

In[14]:=
ResourceFunction[
 "LensManipulate"][<|"FocalLength" -> 9, "Diameter" -> 10|>, "LensColor" -> {LightBlue}, "ArrowColor" -> {LightRed, LightGreen}, "RayColor" -> {White, White, White}, "ShowEquations" -> False, Axes -> True, Background -> Gray, AxesStyle -> Directive[Darker[White]]]
Out[14]=

Publisher

WolframSpecialProjects

Version History

  • 1.1.0 – 12 September 2022
  • 1.0.1 – 02 June 2021
  • 1.0.0 – 17 March 2021

Source Metadata

Related Resources

License Information