Created
July 29, 2019 19:35
-
-
Save objcode/eb3e413973314249b56942d3b778dc81 to your computer and use it in GitHub Desktop.
Solving a very serious problem.
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 python | |
from collections import namedtuple | |
CoC = 0.018 # canon APS-C | |
MIN_DISTANCE = 100 # must focus 300mm away | |
MAX_DISTANCE = 1 * 1000 * 1000 # must focus one KM away | |
FOCALS = [1.3 + (x/10.0) for x in xrange(1, 40 * 10)] | |
FOCUS_DISTANCE = [100 * x for x in xrange(1, 10)] | |
APERATURES = [1.3 + (x/10.0) for x in xrange(1, 10 * 90)] | |
CameraSettings = namedtuple("CameraSettings", "focal aperature focus_distance") | |
Result = namedtuple("Result", "camera_settings min_focus max_focus") | |
def calcHyperfocal(focalLength, aperature): | |
return (focalLength * focalLength) / (aperature * CoC) | |
def calcNearPoint(hyperfocal, distanceMM, focalLength): | |
return (hyperfocal * distanceMM) / (hyperfocal + (distanceMM - focalLength)) | |
def calcFarPoint(hyperfocal, distanceMM, focalLength): | |
return (hyperfocal * distanceMM) / (hyperfocal - (distanceMM - focalLength)) | |
def calcTotalDoF(hyperfocal, distanceMM, focalLength): | |
return (calcFarPoint(hyperfocal, distanceMM, focalLength) - | |
calcNearPoint(hyperfocal, distanceMM, focalLength)) | |
def printValidFocalLengths(): | |
results = [] | |
for focal in FOCALS: | |
for aperature in APERATURES: | |
for distance in FOCUS_DISTANCE: | |
hyperfocal = calcHyperfocal(focal, aperature) | |
near = calcNearPoint(hyperfocal, distance, focal) | |
far = calcFarPoint(hyperfocal, distance, focal) | |
camera = CameraSettings(focal=focal, aperature=aperature, focus_distance=distance) | |
result = Result(camera_settings=camera, min_focus=near, max_focus=far) | |
if result.max_focus > 0: | |
results.append(result) | |
meetsBoth = [item for item in results if item.min_focus <= MIN_DISTANCE and item.max_focus >= MAX_DISTANCE] | |
for item in meetsBoth: | |
print(item) | |
def toFeet(mm): | |
return (3.28084 * mm) / 1000 | |
if __name__ == "__main__": | |
printValidFocalLengths() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment