Skip to content

Instantly share code, notes, and snippets.

@npyoung
Created October 2, 2018 02:21
Show Gist options
  • Save npyoung/5f401a04634182e1f4736a8cf81ad810 to your computer and use it in GitHub Desktop.
Save npyoung/5f401a04634182e1f4736a8cf81ad810 to your computer and use it in GitHub Desktop.
Rough dual lens design
import argparse as ap
if __name__ == "__main__":
parser = ap.ArgumentParser()
parser.add_argument('f', type=float, help="Overall focal length")
parser.add_argument('library', type=int, nargs='+', help="Focal length of available lenses")
args = parser.parse_args()
f = args.f
fs = args.library
design_tbl = []
for f1 in fs:
for f2 in fs:
if f1 <= f2:
d = (1/f1 + 1/f2 - 1/f) * f1 * f2
design_tbl.append({'d':d, 'f1':f1, 'f2':f2})
design_tbl = [x for x in design_tbl if x['d'] <= 0]
design_tbl = sorted(design_tbl, key=lambda x: x['d'])
for entry in design_tbl:
print("{f1:d}, {f2:d} --> {d:0.3f}mm")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment