X-Git-Url: http://git.kpe.io/?p=cl-photo.git;a=blobdiff_plain;f=fov.lisp;h=fba5ce9d91109b423173720ab17f099105406917;hp=2b01e8293c35d223b8e4cfbd8836551277e65024;hb=b95675fd79eb1c5a791267cdc4fc0584c4f14b3b;hpb=eee792a28a53084a949496f7ea1a87012f13f7ce diff --git a/fov.lisp b/fov.lisp index 2b01e82..fba5ce9 100644 --- a/fov.lisp +++ b/fov.lisp @@ -50,26 +50,30 @@ Default is infinity (magnification 0)" (aov-one-dim focal-length (diagonal frame-width frame-height) :projection projection :magnification magnification))) -(defun gaussian-lens (&key object-distance image-distance focal-length) +(defun gaussian-lens (&key object-distance image-distance focal-length (units :mm)) + "object-distance is in units. image-distance and focal-length are in mm." (cond ((and object-distance image-distance (not focal-length)) - (float (/ 1 (+ (/ 1 object-distance) (/ 1 image-distance))))) + ;; Return focal length + (float (/ 1 (+ (/ 1 (length->mm object-distance units)) (/ 1 image-distance))))) ((and object-distance focal-length (not image-distance)) + ;; Return image distance (cond - ((= focal-length object-distance) + ((= focal-length (length->mm object-distance units)) most-positive-double-float) - ((> focal-length object-distance) + ((> focal-length (length->mm object-distance units)) :error) (t - (float (/ 1 (- (/ 1 focal-length) (/ 1 object-distance))))))) + (float (/ 1 (- (/ 1 focal-length) (/ 1 (length->mm object-distance units)))))))) ((and image-distance focal-length (not object-distance)) + ;; Return 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))))))) + (mm->length (float (/ 1 (- (/ 1 focal-length) (/ 1 image-distance)))) units)))) (t (error "Must specify two, and only two, of the parameters: focal-length, image-distance, object-distance")))) @@ -104,12 +108,13 @@ and image distance (mm) for a given image (mm) and object distance (mm)." ((and object-distance (not image-distance) (not magnification)) (setq image-distance (gaussian-lens :focal-length focal-length - :object-distance (length->mm object-distance units)))) + :object-distance object-distance + :units 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))) + (setq object-distance (gaussian-lens + :focal-length focal-length + :image-distance image-distance + :units units))) ((and (not object-distance) (not image-distance) magnification) (setf image-distance (image-distance-magnification focal-length magnification) object-distance (when (numberp image-distance) @@ -154,7 +159,77 @@ focal-length and image-distance are in mm, object-distance is in units" (t (error "Must set two, and only two, of the parameters: image-distance, object-distance, and focal-length.")))) +(defun close-up (&key focal-length object-distance image-distance magnification (units :feet) &aux bellows-factor) + "Computes the parameters for focusing closer than infinity. +Requires two, and only two, of the input parameters. +Returns: focal-length object-distance image-distance magnification bellows-factor." + (cond + ((and focal-length object-distance (not image-distance) (not magnification)) + (setq magnification (magnification :focal-length focal-length + :object-distance object-distance + :units units)) + (setq image-distance (gaussian-lens :focal-length focal-length + :object-distance object-distance + :units units))) + ((and focal-length (not object-distance) image-distance (not magnification)) + (setq magnification (magnification :focal-length focal-length + :image-distance image-distance + :units units)) + (setq object-distance (gaussian-lens :focal-length focal-length + :image-distance image-distance + :units units))) + ((and (not focal-length) object-distance image-distance (not magnification)) + (setq magnification (magnification :object-distance object-distance + :image-distance image-distance + :units units)) + (setq focal-length (gaussian-lens :object-distance object-distance + :image-distance image-distance + :units units))) + ((and focal-length (not object-distance) (not image-distance) magnification) + (setq image-distance (image-distance-magnification focal-length magnification)) + (setq object-distance (gaussian-lens :focal-length focal-length + :image-distance image-distance + :units units))) + ((and (not focal-length) object-distance (not image-distance) magnification) + (setq image-distance (* magnification (length->mm object-distance units))) + (setq focal-length (gaussian-lens :image-distance image-distance + :object-distance object-distance + :units units))) + ((and (not focal-length) (not object-distance) image-distance magnification) + (setq object-distance (mm->length (float (/ image-distance magnification)) units)) + (setq focal-length (gaussian-lens :image-distance image-distance + :object-distance object-distance + :units units))) + (t + (error "Must set two, and only two input parameters: focal-length, image-distance, object-distance, magnifcation."))) + (values focal-length object-distance image-distance magnification (1+ magnification))) + (defun bellows-factor (focal-length object-distance) "Returns the bellows factor, the ratio of effective aperature to actual aperture." (1+ (magnification :focal-length focal-length :object-distance object-distance))) +(defun extension-tube (focal-length &key original-object-distance original-image-distance original-magnification + new-object-distance new-image-distance new-magnification extension-length (units :feet)) + "Computes the parameters for using extension tubes. +Requires: 1. original-object-distance, original-image-distance, or original-magnification + 2. new-object-distance, new-image-distance, new-magnification, or extension-length +Returns: original-object-distance, original-image-distance, original-magnification, original-bellows-factor + new-object-distance, new-image-distance, new-magnification, extension-length." + + (multiple-value-bind (focal-length o-od o-id o-m o-bf) + (close-up :focal-length focal-length :object-distance original-object-distance + :image-distance original-image-distance :magnification original-magnification :units units) + + (cond + (extension-length + (multiple-value-bind (focal-length n-od n-id n-m n-bf) + (close-up :focal-length focal-length :image-distance (+ o-id extension-length) :units units) + (values o-od o-id o-m o-bf n-od n-id n-m n-bf extension-length))) + ((not extension-length) + (multiple-value-bind (focal-length n-od n-id n-m n-bf) + (close-up :focal-length focal-length :object-distance new-object-distance + :image-distance new-image-distance :magnification new-magnification :units units) + (values o-od o-id o-m o-bf n-od n-id n-m n-bf (- n-id o-id))))))) + + +