- (fov-one-dim focal-length frame-width :projection projection)
- (fov-one-dim focal-length frame-height :projection projection)
- (fov-one-dim focal-length (diagonal frame-width frame-height)
- :projection projection)))
-
-(defun fov-distance (focal-length frame-width frame-height distance
- &key (projection :rectilinear))
- "Returns the field of view and image magnificaion ratio at a given distance.
-NOTE: magnification assumes that distance is in the same units as frame size: mm"
- (multiple-value-bind (fov-width fov-height fov-diagonal)
- (fov focal-length frame-width frame-height :projection projection)
- (let* ((d-width (* distance (sin (degrees->radians fov-width))))
- (d-height (* distance (sin (degrees->radians fov-height))))
- (d-diagonal (* distance (sin (degrees->radians fov-diagonal))))
- (mag (/ frame-width d-width)))
- (values d-width d-height d-diagonal mag))))
-
-(defun fov-format (focal-length format &key (projection :rectilinear))
+ (aov-one-dim focal-length frame-width :projection projection :magnification magnification)
+ (aov-one-dim focal-length frame-height :projection projection :magnification magnification)
+ (aov-one-dim focal-length (diagonal frame-width frame-height)
+ :projection projection :magnification magnification)))
+
+(defun gaussian-lens (&key object-distance image-distance focal-length)
+ (cond
+ ((and object-distance image-distance (not focal-length))
+ (float (/ 1 (+ (/ 1 object-distance) (/ 1 image-distance)))))
+ ((and object-distance focal-length (not image-distance))
+ (cond
+ ((= focal-length object-distance)
+ most-positive-double-float)
+ ((> focal-length object-distance)
+ :error)
+ (t
+ (float (/ 1 (- (/ 1 focal-length) (/ 1 object-distance)))))))
+ ((and image-distance focal-length (not object-distance))
+ (cond
+ ((= focal-length image-distance)
+ most-positive-double-float)
+ ((> focal-length image-distance)
+ :error)
+ (t
+ (float (/ 1 (- (/ 1 focal-length) (/ 1 image-distance)))))))
+ (t
+ (error "Must specify two, and only two, of the parameters: focal-length, image-distance, object-distance"))))
+
+
+(defun image-distance-magnification (focal-length magnification)
+ "Returns the image distance for a focused object at distance using the Gaussian
+Lens Equation."
+ (* focal-length (1+ magnification)))
+
+(defun %fov (focal-length frame-width frame-height object-distance image-distance units
+ &optional (projection :rectilinear))
+ "Returns the field of view (units), magnification ratio, object-distance (units),
+and image distance (mm) for a given image (mm) and object distance (mm)."
+ (unless (numberp image-distance)
+ (return-from %fov image-distance))
+ (unless (numberp object-distance)
+ (return-from %fov object-distance))
+ (let ((mag (/ image-distance (length->mm object-distance units))))
+ (multiple-value-bind (aov-width aov-height aov-diagonal)
+ (aov focal-length frame-width frame-height :projection projection
+ :magnification mag)
+ (let* ((d-width (* 2 object-distance (tan (degrees->radians (/ aov-width 2)))))
+ (d-height (* 2 object-distance (tan (degrees->radians (/ aov-height 2)))))
+ (d-diagonal (* 2 object-distance (tan (degrees->radians (/ aov-diagonal 2))))))
+ (values d-width d-height d-diagonal mag object-distance image-distance)))))
+
+(defun fov (focal-length frame-width frame-height
+ &key object-distance image-distance magnification
+ (units :feet)
+ (projection :rectilinear))
+ (cond
+ ((and object-distance (not image-distance) (not magnification))
+ (setq image-distance (gaussian-lens
+ :focal-length focal-length
+ :object-distance (length->mm object-distance units))))
+ ((and (not object-distance) image-distance (not magnification))
+ (setq object-distance (mm->length (gaussian-lens
+ :focal-length focal-length
+ :image-distance image-distance)
+ units)))
+ ((and (not object-distance) (not image-distance) magnification)
+ (setf image-distance (image-distance-magnification focal-length magnification)
+ object-distance (when (numberp image-distance)
+ (mm->length (/ image-distance magnification) units))))
+ (t
+ (error "Must set one, and only one, of the parameters: image-distance, object-distance, or magnification.")))
+
+ (%fov focal-length frame-width frame-height object-distance image-distance units
+ projection))
+
+(defun aov-format (focal-length format &key (projection :rectilinear))