Last active
September 30, 2022 17:30
-
-
Save jasonrobot/b2bca47df312744faa24bf269e2bf006 to your computer and use it in GitHub Desktop.
calculate hyperfocal distances
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
#!/usr/bin/env ruby | |
require "optparse" | |
# default values for command line args | |
focal_length = 50 | |
apertures = [16, 11, 8, 5.6] | |
circle_of_confusion = 0.03 | |
use_feet = false | |
OptionParser.new do |opts| | |
opts.on( | |
'-f FOCAL_LENGTH', | |
'--focal-length=FOCAL_LENGTH', | |
Numeric, | |
'Lens focal length' | |
) do |value| | |
focal_length = value | |
end | |
opts.on( | |
'-a apertures', | |
'--aperture apertures', | |
Array, | |
'Apertures to report for.' | |
) do |values| | |
apertures = values.map do |value| | |
value.to_f | |
end.sort.reverse | |
end | |
opts.on( | |
'-c coc', | |
Numeric, | |
'Circle of confusion' | |
) do |value| | |
circle_of_confusion = value | |
end | |
opts.on( | |
'-F', | |
'--feet', | |
'Use shitty units.' | |
) do | |
use_feet = true | |
end | |
end.parse! | |
def find_hyperfocal( | |
focal_length, | |
aperture, | |
circle_of_confusion = 0.03 | |
) | |
f_sq = (focal_length * focal_length) | |
(f_sq / (aperture * circle_of_confusion)) + focal_length | |
end | |
puts "for f = #{focal_length} #{circle_of_confusion}" | |
apertures.each do |aperture| | |
hf = find_hyperfocal( | |
focal_length, | |
aperture, | |
circle_of_confusion | |
)./(1000).round(1) | |
hf *= 3.281 if use_feet | |
hf_2 = (hf / 2).round(1) | |
puts "H at #{aperture} is #{hf}. H/2 = #{hf_2}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment