r10418: Automated commit for cl-photo debian-version-0.1-1
[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 fov-one-dim (focal-length frame-size 
23                                  &key (projection :rectilinear))
24   (ecase projection
25     (:rectilinear
26      (radians->degrees (* 2 (atan (/ frame-size 2 focal-length)))))
27     (:equisolid 
28      (radians->degrees (* 4 (asin (/ frame-size 4 focal-length)))))
29     (:equidistance 
30      (radians->degrees (/ (* 2 frame-size) focal-length)))
31     (:orthogonal
32      (radians->degrees (* 2 (asin (/ frame-size 2 focal-length)))))
33     (:stereographic
34      (radians->degrees (* 4 (atan (/ frame-size 4 focal-length)))))
35     ))
36     
37   
38 (defun fov (focal-length frame-width frame-height
39                          &key (projection :rectilinear))
40   "Returns the angle of field of view for a focal length and frame size at infinity"
41   (values
42    (fov-one-dim focal-length frame-width :projection projection)
43    (fov-one-dim focal-length frame-height :projection projection)
44    (fov-one-dim focal-length (diagonal frame-width frame-height)
45                 :projection projection)))
46
47 (defun fov-distance (focal-length frame-width frame-height distance
48                                   &key (projection :rectilinear))
49   "Returns the field of view and image magnificaion ratio at a given distance.
50 NOTE: magnification assumes that distance is in the same units as frame size: mm"
51   (multiple-value-bind (fov-width fov-height fov-diagonal)
52       (fov focal-length frame-width frame-height :projection projection)
53     (let* ((d-width (* distance (sin (degrees->radians fov-width))))
54            (d-height (* distance (sin (degrees->radians fov-height))))
55            (d-diagonal (* distance (sin (degrees->radians fov-diagonal))))
56            (mag (/ frame-width d-width))) 
57       (values d-width d-height d-diagonal mag))))
58
59 (defun fov-format (focal-length format &key (projection :rectilinear))
60   "Returns the angle of field of view for a focal length and frame size at infinity"
61   (let ((dim (format-dimensions format))) 
62     (fov focal-length (car dim) (cdr dim) :projection projection)))