Class: Optical::Lens

Inherits:
Object
  • Object
show all
Defined in:
lib/optical/lens.rb

Overview

A representation of a simple thin lens en.wikipedia.org/wiki/Lens_(optics)

Direct Known Subclasses

PlanoConvexLens

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Lens

Returns a new instance of Lens.



9
10
11
# File 'lib/optical/lens.rb', line 9

def initialize(**options)
    options.each {|k,v| respond_to?(k) ? instance_variable_set("@#{k}", v) : raise(ArgumentError, "Unknown argument: '#{k}'") }
end

Instance Attribute Details

#center_thicknessObject (readonly)

Returns the value of attribute center_thickness.



28
29
30
# File 'lib/optical/lens.rb', line 28

def center_thickness
  @center_thickness
end

#clear_diameterObject (readonly) Also known as: clear_aperture



15
16
17
# File 'lib/optical/lens.rb', line 15

def clear_diameter
    @clear_diameter || (2*@clear_radius)
end

#clear_radiusObject (readonly)



22
23
24
# File 'lib/optical/lens.rb', line 22

def clear_radius
    @clear_radius || (@clear_diameter && @clear_diameter/2)
end

#diameterObject



32
33
34
# File 'lib/optical/lens.rb', line 32

def diameter
    @diameter || 2*@radius
end

#edge_thicknessNumber

Returns the thickness of the Optical::Lens at its edge.

Returns:



38
39
40
# File 'lib/optical/lens.rb', line 38

def edge_thickness
  @edge_thickness
end

#focal_lengthObject (readonly)

Returns the value of attribute focal_length.



7
8
9
# File 'lib/optical/lens.rb', line 7

def focal_length
  @focal_length
end

#numerical_apertureObject (readonly)



42
43
44
# File 'lib/optical/lens.rb', line 42

def numerical_aperture
    Math.sin(Math.atan2(clear_radius || radius, focal_length))
end

#radiusObject (readonly)



48
49
50
# File 'lib/optical/lens.rb', line 48

def radius
    @radius || @diameter/2
end

#thicknessObject



54
55
56
# File 'lib/optical/lens.rb', line 54

def thickness
    [@center_thickness, @edge_thickness].max
end