def normal(self, p): # sphere + conic contribution r2 = p[0] * p[0] + p[1] * p[1] r = sqrt(r2) e = self.cv / sqrt(1. - self.ec * self.cv * self.cv * r2) # polynomial asphere contribution - compute using Horner's Rule e_asp = 0.0 if r == 0.0: r_pow = 1.0 else: # Initialize to 1/r because we multiply by r's components p[0] and # p[1] at the final normalization step. r_pow = 1.0 / r c_coef = 1.0 for coef in self.coefs[1:self.max_nonzero_coef]: e_asp += c_coef * coef * r_pow c_coef += 1.0 r_pow *= r e_tot = e + e_asp return normalize(np.array([-e_tot * p[0], -e_tot * p[1], 1.0]))
def test(): s1 = Spherical(0.0) s2 = Spherical(0.1) dir0 = np.array([0., 0., 1.]) v1 = normalize(np.array([1., 1., 1.])) p0 = np.array([0., 0., -1.]) p1 = np.array([0., 1., -1.]) p0s1 = s1.intersect(p0, dir0) print(p0s1) p1s1 = s1.intersect(p1, dir0) print(p1s1) p0s2 = s2.intersect(p0, dir0) print(p0s2) p1s2 = s2.intersect(p1, dir0) print(p1s2) dir_p1s2 = s2.normal(p1s2[1]) print(dir_p1s2) print("pass")
def setup_canonical_coords(opt_model, fld, wvl, image_pt=None): osp = opt_model.optical_spec seq_model = opt_model.seq_model fod = osp.parax_data.fod if fld.chief_ray is None: ray, op, wvl = trace_base(opt_model, [0., 0.], fld, wvl) fld.chief_ray = RayPkg(ray, op, wvl) cr = fld.chief_ray if image_pt is None: image_pt = cr.ray[-1][mc.p] # cr_exp_pt: E upper bar prime: pupil center for pencils from Q # cr_exp_pt, cr_b4_dir, cr_dst cr_exp_seg = rt.transfer_to_exit_pupil( seq_model.ifcs[-2], (cr.ray[-2][mc.p], cr.ray[-2][mc.d]), fod.exp_dist) cr_exp_pt = cr_exp_seg[mc.p] cr_exp_dist = cr_exp_seg[mc.dst] img_dist = seq_model.gaps[-1].thi img_pt = np.array(image_pt) img_pt[2] += img_dist # R' radius of reference sphere for O' ref_sphere_vec = img_pt - cr_exp_pt ref_sphere_radius = np.linalg.norm(ref_sphere_vec) ref_dir = normalize(ref_sphere_vec) ref_sphere = (image_pt, cr_exp_pt, cr_exp_dist, ref_dir, ref_sphere_radius) z_dir = seq_model.z_dir[-1] wl = seq_model.index_for_wavelength(wvl) n_obj = seq_model.rndx[0][wl] n_img = seq_model.rndx[-1][wl] ref_sphere_pkg = (ref_sphere, osp.parax_data, n_obj, n_img, z_dir) fld.ref_sphere = ref_sphere_pkg return ref_sphere_pkg, cr
def normal(self, p): """Returns the unit normal of the profile at point *p*. """ return normalize(self.df(p))
def normal(self, p): return normalize(np.array( [-self.cv*p[0], -self.cv*p[1], 1.0-(self.cc+1.0)*self.cv*p[2]]))