r10440: add tables
[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   (if (= focal-length object-distance)
57       0
58     (float (/ 1 (- (/ 1 focal-length) (/ 1 object-distance))))))
59
60 (defun fov (focal-length frame-width frame-height object-distance
61                          &key (projection :rectilinear))
62   "Returns the field of view and image magnificaion ratio at a given distance."
63   (let* ((image-distance (image-distance focal-length object-distance))
64          (magnification (/ image-distance object-distance)))
65     (multiple-value-bind (aov-width aov-height aov-diagonal)
66         (aov focal-length frame-width frame-height :projection projection
67              :magnification magnification)
68       (let* ((d-width (* 2 object-distance (tan (degrees->radians (/ aov-width 2)))))
69              (d-height (* 2 object-distance (tan (degrees->radians (/ aov-height 2)))))
70              (d-diagonal (* 2 object-distance (tan (degrees->radians (/ aov-diagonal 2))))))
71         (values d-width d-height d-diagonal magnification)))))
72
73 (defun aov-format (focal-length format &key (projection :rectilinear))
74   "Returns the angle of field of view for a focal length and frame size at infinity"
75   (let ((dim (imager-dimensions format))) 
76     (aov focal-length (car dim) (cdr dim) :projection projection)))
77
78 (defun magnification (focal-length distance)
79   "Returns the image magnification: the ratio of image size to objecct size."
80   (float (/ focal-length (- distance focal-length))))
81
82 (defun bellows-factor (focal-length distance)
83   "Returns the bellows factor, the ratio of effective aperature to actual aperture."
84   (1+ (magnification focal-length distance)))
85