r10409: updates for cl-photo
[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 Rosenberg.
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
14 ;;;;
15 ;;;; *************************************************************************
16
17 (in-package #:photo)
18
19 (defun fov-one-dim (focal-length frame-size 
20                                  &key (projection :rectilinear))
21   (ecase projection
22     (:rectilinear
23      (radians->degrees (* 2 (atan (/ frame-size 2 focal-length)))))
24     (:equisolid 
25      (radians->degrees (* 4 (asin (/ frame-size 4 focal-length)))))
26     (:equidistance 
27      (radians->degrees (/ (* 2 frame-size) focal-length)))
28     (:orthogonal
29      (radians->degrees (* 2 (asin (/ frame-size 2 focal-length)))))
30     (:stereographic
31      (radians->degrees (* 4 (atan (/ frame-size 4 focal-length)))))
32     ))
33     
34   
35 (defun fov (focal-length frame-width frame-height
36                          &key (projection :rectilinear))
37   "Returns the angle of field of view for a focal length and frame size at infinity"
38   (values
39    (fov-one-dim focal-length frame-width :projection projection)
40    (fov-one-dim focal-length frame-height :projection projection)
41    (fov-one-dim focal-length (diagonal frame-width frame-height)
42                 :projection projection)))
43
44 (defun fov-distance (focal-length frame-width frame-height distance
45                                   &key (projection :rectilinear))
46   "Returns the field of view and image magnificaion ratio at a given distance.
47 NOTE: magnification assumes that distance is in the same units as frame size: mm"
48   (multiple-value-bind (fov-width fov-height fov-diagonal)
49       (fov focal-length frame-width frame-height :projection projection)
50     (let* ((d-width (* distance (sin (degrees->radians fov-width))))
51            (d-height (* distance (sin (degrees->radians fov-height))))
52            (d-diagonal (* distance (sin (degrees->radians fov-diagonal))))
53            (mag (/ frame-width d-width))) 
54       (values d-width d-height d-diagonal mag))))
55
56 (defun fov-format (focal-length format &key (projection :rectilinear))
57   "Returns the angle of field of view for a focal length and frame size at infinity"
58   (let ((dim (format-dimensions format))) 
59     (fov focal-length (car dim) (cdr dim) :projection projection)))