1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Depth of field functions for cl-photo
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: April 2005
10 ;;;; $Id: package.lisp 8596 2004-02-03 18:32:50Z kevin $
12 ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin Rosenberg.
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
15 ;;;; *************************************************************************
19 ;; Based on http://www.photostuff.co.uk/dofmstr.htm
21 (defun dof (focal-length f-stop distance coc)
22 "Returns depth of field as fives values:
23 near dof, far dof, total dof, near point, far point"
24 (let* ((aperature (/ focal-length f-stop))
25 (numerator (* distance coc (- distance focal-length)))
26 (factor-1 (* focal-length aperature))
27 (factor-2 (* coc (- distance focal-length)))
28 (near (/ numerator (+ factor-1 factor-2)))
29 (far (/ numerator (- factor-1 factor-2)))
31 (values near far depth (- distance near) (+ distance far))))
33 (defun dof-feet (focal-length f-stop distance coc)
34 (multiple-value-bind (near-dof far-dof total-dof near-point far-point)
35 (dof focal-length f-stop (feet->mm distance) coc)
36 (values (mm->feet near-dof) (mm->feet far-dof) (mm->feet total-dof)
37 (mm->feet near-point) (mm->feet far-point))))
39 (defun dof-meters (focal-length f-stop distance coc)
40 (multiple-value-bind (near-dof far-dof total-dof near-point far-point)
41 (dof focal-length f-stop (* 1000 distance) coc)
42 (values (* 0.001 near-dof) (* 0.001 far-dof) (* 0.001 total-dof)
43 (* 0.001 near-point) (* 0.001 far-point))))
46 (defun hyperfocal (focal-length f-stop coc)
47 (+ focal-length (/ (* focal-length focal-length) (* f-stop coc))))
49 (defun hyperfocal-feet (focal-length f-stop coc)
50 (mm->feet (hyperfocal focal-length f-stop coc)))