23ca941d517f28b73f5a0b96ac81107442ba7e76
[cl-photo.git] / fov.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          fov.lisp
6 ;;;; Purpose:       Field of view functions for cl-photo
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; cl-photo users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;;
18 ;;;; *************************************************************************
19
20 (in-package #:photo)
21
22 (defun aov-one-dim (focal-length frame-size 
23                                  &key (projection :rectilinear)
24                                  (magnification 0))
25   "Returns the angle of view in one dimension. Default is infinity which
26 has an magnification of 0."
27   (ecase projection
28     (:rectilinear
29      (radians->degrees (* 2 (atan (/ frame-size 2 focal-length
30                                      (1+ magnification))))))
31     (:equisolid 
32      (radians->degrees (* 4 (asin (/ frame-size 4 focal-length)))))
33     (:equidistance 
34      (radians->degrees (/ (* 2 frame-size) focal-length)))
35     (:orthogonal
36      (radians->degrees (* 2 (asin (/ frame-size 2 focal-length)))))
37     (:stereographic
38      (radians->degrees (* 4 (atan (/ frame-size 4 focal-length)))))
39     ))
40     
41   
42 (defun aov (focal-length frame-width frame-height
43                          &key (projection :rectilinear)
44                          (magnification 0))
45   "Returns the angle of field of view for a focal length and frame size. 
46 Default is infinity (magnification 0)"
47   (values
48    (aov-one-dim focal-length frame-width :projection projection :magnification magnification)
49    (aov-one-dim focal-length frame-height :projection projection :magnification magnification)
50    (aov-one-dim focal-length (diagonal frame-width frame-height)
51                 :projection projection :magnification magnification)))
52
53 (defun image-distance (focal-length object-distance)
54   "Returns the image distance for a focused object at distance using the Gaussian 
55 Lens Equation."
56   (float (/ 1 (- (/ 1 focal-length) (/ 1 object-distance)))))
57
58 (defun fov (focal-length frame-width frame-height object-distance
59                          &key (projection :rectilinear))
60   "Returns the field of view and image magnificaion ratio at a given distance."
61   (let* ((image-distance (image-distance focal-length object-distance))
62          (magnification (/ image-distance object-distance)))
63     (multiple-value-bind (aov-width aov-height aov-diagonal)
64         (aov focal-length frame-width frame-height :projection projection
65              :magnification magnification)
66       (let* ((d-width (* 2 object-distance (tan (degrees->radians (/ aov-width 2)))))
67              (d-height (* 2 object-distance (tan (degrees->radians (/ aov-height 2)))))
68              (d-diagonal (* 2 object-distance (tan (degrees->radians (/ aov-diagonal 2))))))
69         (values d-width d-height d-diagonal magnification)))))
70
71 (defun aov-format (focal-length format &key (projection :rectilinear))
72   "Returns the angle of field of view for a focal length and frame size at infinity"
73   (let ((dim (format-dimensions format))) 
74     (aov focal-length (car dim) (cdr dim) :projection projection)))
75
76 (defun magnification (focal-length distance)
77   "Returns the image magnification: the ratio of image size to objecct size."
78   (float (/ focal-length (- distance focal-length))))
79
80 (defun bellows-factor (focal-length distance)
81   "Returns the bellows factor, the ratio of effective aperature to actual aperture."
82   (1+ (magnification focal-length distance)))
83