def conic_sag(test_vector): """ Computation of conic sag equals explicit calculation. """ coordinate_system = LocalCoordinates(name="root") radius = 10.0 conic_constant = -1.5 curvature = 1. / radius maxradius = (math.sqrt(1. / ((1 + conic_constant) * curvature**2)) if conic_constant > -1 else abs(radius)) values = (2 * test_vector - 1.) * maxradius x_coordinate = values[0] y_coordinate = values[1] shape = Conic(coordinate_system, curv=curvature, cc=conic_constant) sag = shape.getSag(x_coordinate, y_coordinate) # comparison with explicitly entered formula assert np.allclose( sag, (curvature * (x_coordinate**2 + y_coordinate**2) / (1. + np.sqrt(1. - (1. + conic_constant) * curvature**2 * (x_coordinate**2 + y_coordinate**2)))))
def initShConic(self, curv=0., cc=0., **kwargs): shapeclass = None if kwargs.has_key("surface"): shapeclass = kwargs["surface"].shape curv = shapeclass.curvature.evaluate() cc = shapeclass.conic.evaluate() else: shapeclass = Conic(self.__obj.LocalCoordinatesLink.getLC(), curv=curv, cc=cc) self.__obj.addProperty("App::PropertyFloat", "curv", "Shape", "central curvature").curv = curv self.__obj.addProperty("App::PropertyFloat", "cc", "Shape", "conic constant").cc = cc self.__obj.shapeclass = shapeclass
def conic_grad(test_vector): """ Computation of conic grad equals explicit calculation. """ coordinate_system = LocalCoordinates(name="root") radius = 10.0 conic_constant = -1.5 curvature = 1. / radius maxradius = (math.sqrt(1. / ((1 + conic_constant) * curvature**2)) if conic_constant > -1 else abs(radius)) values = (2 * test_vector - 1.) * maxradius x = values[0] y = values[1] shape = Conic(coordinate_system, curv=curvature, cc=conic_constant) gradient = shape.getGrad(x, y) comparison = np.zeros_like(gradient) comparison[2, :] = 1. comparison[0] = (-curvature**3 * x * (conic_constant + 1) * (x**2 + y**2) / (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) * (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) + 1)**2) - 2 * curvature * x / (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) + 1)) comparison[1] = (-curvature**3 * y * (conic_constant + 1) * (x**2 + y**2) / (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) * (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) + 1)**2) - 2 * curvature * y / (np.sqrt(-curvature**2 * (conic_constant + 1) * (x**2 + y**2) + 1) + 1)) comparison = comparison * gradient[ 2] # comparison and gradient are calculated differently assert np.allclose(gradient, comparison)
def initShExplicit(self, **kwargs): # this function offers the flexibility to use function objects with tunable parameters # TODO: implement self.__obj.shapeclass = Conic(curv=0, cc=0)
(si * 4.529e-12, -2.085)]), apert=CircularAperture(lcS2, 40.0)) D2Psurf = Surface(lcD2prime) D3surf = Surface(lcD3) #S3surf = Surface(lcS3, shape=Conic(lcS3, curv=si*1./108.187, cc=0.0001), apert=CircularAperture(lcS3, 100.0)) S3surf = Surface(lcS3, shape=Biconic(lcS3, curvy=si * 1. / 108.187, curvx=si * 1. / 73.105, coefficients=[(0., 0.), (-si * 5.542e-7, -0.08), (-si * 8.176e-11, -1.379)]), apert=CircularAperture(lcS3, 40.0)) D3Psurf = Surface(lcD3prime) D4surf = Surface(lcD4) S4surf = Surface(lcS4, shape=Conic(lcS4, curv=1. / 77.772), apert=CircularAperture(lcS4, 40.0)) D4Psurf = Surface(lcD4prime) imgsurf = Surface(lcimage) elem = OpticalElement(lc0, name="HUD") elem.addMaterial("air", air) elem.addMaterial("glass", glass) elem.addSurface("object", objsurf, (None, None)) elem.addSurface("d1", D1surf, (None, None)) elem.addSurface("s1", S1surf, (None, "glass")) elem.addSurface("d1p", D1Psurf, ("glass", "glass")) elem.addSurface("d2", D2surf, ("glass", "glass")) elem.addSurface("s2", S2surf, ("glass", "glass"))
wavelength = 0.5876e-3 # definition of optical system s = OpticalSystem() lc0 = s.addLocalCoordinateSystem(LocalCoordinates(name="stop", decz=0.0), refname=s.rootcoordinatesystem.name) lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=5.0), refname=lc0.name) # objectDist lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=20.0), refname=lc1.name) lc3 = s.addLocalCoordinateSystem(LocalCoordinates(name="image", decz=100.0), refname=lc2.name) stopsurf = Surface(lc0) frontsurf = Surface(lc1, shape=Conic(lc1), apert=CircularAperture(lc1, 12.7)) backsurf = Surface(lc2, shape=Asphere(lc2, curv=-1. / 50.0, cc=-1., coefficients=[0.0, 0.0, 0.0]), apert=CircularAperture(lc2, 12.7)) image = Surface(lc3) elem = OpticalElement(lc0, name="asphereelement") bk7 = ConstantIndexGlass(lc1, n=1.5168) elem.addMaterial("BK7", bk7) elem.addSurface("stop", stopsurf, (None, None))