r10404: Initial import
[cl-photo.git] / dof.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          dof.lisp
6 ;;;; Purpose:       Depth of field functions for cl-photo
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id: package.lisp 8596 2004-02-03 18:32:50Z kevin $
11 ;;;;
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.
14 ;;;;
15 ;;;; *************************************************************************
16
17 (in-package #:photo)
18
19 ;; Based on http://www.photostuff.co.uk/dofmstr.htm
20
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)))
30          (depth (+ far near)))
31     (values near far depth (- distance near) (+ distance far))))
32
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))))
38
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))))
44
45
46 (defun hyperfocal (focal-length f-stop coc)
47   (+ focal-length (/ (* focal-length focal-length) (* f-stop coc))))
48
49 (defun hyperfocal-feet (focal-length f-stop coc)
50   (mm->feet (hyperfocal focal-length f-stop coc)))
51
52