scan of worm works now
[woropt.git] / lens / helpers.lisp
blob3725372afe580727b2f3606a0dc960c31088d8cb
1 (in-package :lens)
3 ;; |
4 ;; -------- |
5 ;; SS \--- |
6 ;; \-- |
7 ;; X-----+-------------------------------
8 ;; /- \ |
9 ;; /- \ |
10 ;; nf=h /- \ | D/2=R
11 ;; /- \|
12 ;; /- |
13 ;; /- alpha |
14 ;; ---------------------+----------------------------------------
15 ;; nf |
17 ;; sin(alpha) = R/nf
19 (defmethod back-focal-plane-radius ((objective objective))
20 (declare (values double-float &optional))
21 (with-slots (focal-length numerical-aperture) objective
22 (* focal-length numerical-aperture)))
24 (defun focal-length-from-magnification (mag)
25 (declare (double-float mag)
26 (values double-float &optional))
27 (/ 164.5 mag))
28 #+nil
29 (focal-length-from-magnification 63d0)
31 (defun make-objective (&key (magnification 63d0)
32 (numerical-aperture 1.38d0)
33 (immersion-index 1.515d0)
34 (center (v))
35 (normal (v 0 0 1)))
36 (let* ((f (focal-length-from-magnification magnification))
37 (o (make-instance 'objective
38 :bfp-radius 1d0 ;; these need to be generated
39 :focal-length f
40 :radius 1d0
41 :numerical-aperture numerical-aperture
42 :immersion-index immersion-index
43 :center center
44 :normal normal))
45 (bfp-radius (back-focal-plane-radius o)))
46 (make-instance 'objective
47 :bfp-radius bfp-radius
48 :focal-length f
49 :radius (* 10 bfp-radius)
50 :numerical-aperture numerical-aperture
51 :immersion-index immersion-index
52 :center center
53 :normal normal)))
54 #+nil
55 (make-objective)
57 (defmethod get-ray-behind-objective ((obj objective)
58 x-mm y-mm bfp-x/r bfp-y/r)
59 "Take a point on the back focal plane and a point in the sample and
60 calculate the ray direction ro that leaves the objective. The return
61 values are the exiting ray with normalized direction from the
62 principal plane and the entering ray from the bfp."
63 (declare (double-float x-mm y-mm)
64 ((double-float -1d0 1d0) bfp-x/r bfp-y/r)
65 (values ray ray &optional))
66 (with-slots (bfp-radius center
67 (f focal-length)) obj
68 (let* ((theta (find-inverse-ray-angle obj x-mm y-mm))
69 (phi (atan y-mm x-mm))
70 (start (v+ center (make-vec (* bfp-radius bfp-x/r)
71 (* bfp-radius bfp-y/r)
72 (- f))))
73 (enter (make-instance 'ray
74 :start start
75 :direction (v-spherical theta phi)))
76 (exit (refract enter obj))
77 (norm-exit (make-instance
78 'ray
79 :start (vector::start exit)
80 :direction (normalize (vector::direction exit)))))
81 (values norm-exit enter))))
83 #+nil
84 (get-ray-behind-objective .1d0 .1d0 0d0 0d0)