;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*- ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; ;;;; Name: dof.lisp ;;;; Purpose: Depth of field functions for cl-photo ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: April 2005 ;;;; ;;;; $Id: package.lisp 8596 2004-02-03 18:32:50Z kevin $ ;;;; ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin Rosenberg. ;;;; Rights of modification and redistribution are in the LICENSE file. ;;;; ;;;; ************************************************************************* (in-package #:photo) ;; Based on http://www.photostuff.co.uk/dofmstr.htm (defun dof (focal-length f-stop distance coc) "Returns depth of field as fives values: near dof, far dof, total dof, near point, far point" (let* ((aperature (/ focal-length f-stop)) (numerator (* distance coc (- distance focal-length))) (factor-1 (* focal-length aperature)) (factor-2 (* coc (- distance focal-length))) (near (/ numerator (+ factor-1 factor-2))) (far (/ numerator (- factor-1 factor-2))) (depth (+ far near))) (values near far depth (- distance near) (+ distance far)))) (defun dof-feet (focal-length f-stop distance coc) (multiple-value-bind (near-dof far-dof total-dof near-point far-point) (dof focal-length f-stop (feet->mm distance) coc) (values (mm->feet near-dof) (mm->feet far-dof) (mm->feet total-dof) (mm->feet near-point) (mm->feet far-point)))) (defun dof-meters (focal-length f-stop distance coc) (multiple-value-bind (near-dof far-dof total-dof near-point far-point) (dof focal-length f-stop (* 1000 distance) coc) (values (* 0.001 near-dof) (* 0.001 far-dof) (* 0.001 total-dof) (* 0.001 near-point) (* 0.001 far-point)))) (defun hyperfocal (focal-length f-stop coc) (+ focal-length (/ (* focal-length focal-length) (* f-stop coc)))) (defun hyperfocal-feet (focal-length f-stop coc) (mm->feet (hyperfocal focal-length f-stop coc)))