示例#1
0
 def __init__(self, radius=1.):
     """
     Arguments:  
     radius - Set as the sphere's radius.
     
     Private attributes:
     _rad - radius of the sphere, a float. 
     """
     QuadricGM.__init__(self)
     self.set_radius(radius)
示例#2
0
 def __init__(self, a=1.0, b=1.0):
     """               
     Arguments: 
     a, b - describe the paraboloid as z = (x/a)**2 + (y/b)**2
         (sorry, legacy)
     
     Private attributes:                                                                  
     a, b - describe the paraboloid as z = a*x**2 + b*y**2
     """
     QuadricGM.__init__(self)
     self.a = 1.0 / (a ** 2)
     self.b = 1.0 / (b ** 2)
示例#3
0
	def __init__(self, a=1., b=1., c=1., d=0., e=0., f=0.):
		"""			   
		Arguments: 
		a, b, c, d, e, f: z = ax**2 + by**2 + cxy + dx + ey + f
		
		""" 
		QuadricGM.__init__(self)
		self.a = a
		self.b = b
		self.c = c
		self.d = d
		self.e = e
		self.f = f
示例#4
0
文件: cone.py 项目: jdpipe/tracer
 def __init__(self, c = 1., a = 0.):
     """          
     Arguments: 
     c - cone gradient (r/h)
     a - position of cone apex on z axis
     
     Cone equation is x**2 + y**2 = (c*(z-a))**2
     
     Private attributes:                                                      
     c - cone gradient (r/h)
     a - position of cone apex on z axis
     """ 
     QuadricGM.__init__(self)
     self.c = float(c)
     self.a = float(a)
示例#5
0
	def _select_coords(self, coords, prm):
		"""
		Choose between two intersection points on a quadric surface.
		This implementation extends QuadricGM's behaviour by not choosing
		intersections outside the rectangular aperture.
		
		Arguments:
		coords - a 2 by 3 by n array whose each column is the global coordinates
			of one intersection point of a ray with the sphere.
		prm - the corresponding parametric location on the ray where the
			intersection occurs.

		Returns:
		The index of the selected intersection, or None if neither will do.
		"""
		select = QuadricGM._select_coords(self, coords, prm)

		coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis = 1)
		# assumed no additional parameters to coords, axis = 1
		local = N.sum(N.linalg.inv(self._working_frame)[None,:2,:,None] * \
			coords[:,None,:,:], axis=2)

		abs_x = abs(local[:,0,:])
		abs_y = abs(local[:,1,:])
		outside = abs_x > self._w
		outside |= abs_y > self._h
		inside = (~outside) & (prm > 1e-6)

		select[~N.logical_or(*inside)] = N.nan
		one_hit = N.logical_xor(*inside)
		select[one_hit] = N.nonzero(inside.T[one_hit,:])[1]

		return select
示例#6
0
    def _select_coords(self, coords, prm):
        """
        Choose between two intersection points on a quadric surface.
        This implementation extends QuadricGM's behaviour by not choosing
        intersections outside the circular aperture.
        
        Arguments:
        coords - a 2 by 3 by n array whose each column is the global coordinates
            of one intersection point of a ray with the sphere.
        prm - the corresponding parametric location on the ray where the
            intersection occurs.

        Returns:
        The index of the selected intersection, or None if neither will do.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))), axis=1)
        local_z = N.sum(N.linalg.inv(self._working_frame)[None, 2, :, None] * coords, axis=1)
        under_cut = (local_z <= self._h) & (prm > 0)

        select[~N.logical_or(*under_cut)] = N.nan
        one_hit = N.logical_xor(*under_cut)
        select[one_hit] = N.nonzero(under_cut.T[one_hit, :])[1]

        return select
示例#7
0
    def _select_coords(self, coords, prm):
        """
        Choose between two intersection points on a quadric surface.
        This implementation extends QuadricGM's behaviour by not choosing
        intersections outside the hexagon aperture.
        
        Arguments:
        coords - a 2 by 3 by n array whose each column is the global coordinates
            of one intersection point of a ray with the sphere. Why 2 by three here, doesn't concatenate with 
        prm - the corresponding parametric location on the ray where the
            intersection occurs.

        Returns:
        The index of the selected intersection, or None if neither will do.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate(
            (coords, N.ones((2, 1, coords.shape[2]))), axis=1
        )  # n rays two clusters of row matrices with n elements of one concatenated horizontally 2*4*n ats.
        local = N.sum(N.linalg.inv(self._working_frame)[None, :2, :, None] * coords[:, None, :, :], axis=2)
        # working frame, a 4*4 homogeneous transform array representing the surface frame in the global coordinates. This is an elementwise multiplication, interesting.
        # 2*4 and three extra layers. Imitation of a dot product. Now the coordinates transferred back to the local ones.
        abs_x = abs(local[:, 0, :])
        abs_y = abs(local[:, 1, :])
        outside = abs_x > N.sqrt(3) * self._R / 2.0
        outside |= abs_y > self._R - N.tan(N.pi / 6.0) * abs_x
        inside = (~outside) & (prm > 1e-9)

        select[~N.logical_or(*inside)] = N.nan
        one_hit = N.logical_xor(*inside)
        select[one_hit] = N.nonzero(inside.T[one_hit, :])[1]

        return select
示例#8
0
	def _select_coords(self, coords, prm):
		select = QuadricGM._select_coords(self, coords, prm) # defaults
        
		coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis=1)
		local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * coords[:,None,:,:], axis=2)

		bottom_hem = (local[:,2,:] <= 0) & (prm > 0)
		in_facet = (N.abs(local[:,0,:])<=self.lx/2.) & (N.abs(local[:,1,:])<=self.ly/2.)
		good = N.logical_and(bottom_hem,in_facet)
		select[~N.logical_or(*good)] = N.nan
		one_hit = N.logical_xor(*good)
		select[one_hit] = N.nonzero(good[:,one_hit])[0]
		return select
示例#9
0
 def _select_coords(self, coords, prm):
     """
     Select from dual intersections by vetting out rays in the upper
     hemisphere, or if both are below use the default behaviour of choosing
     the first hit.
     """
     select = QuadricGM._select_coords(self, coords, prm) # defaults
     
     coords = N.concatenate((coords, N.ones((2,1,coords.shape[2]))), axis=1)
     local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * \
         coords[:,None,:,:], axis=2)
     bottom_hem = (local[:,2,:] <= 0) & (prm > 0)
     
     select[~N.logical_or(*bottom_hem)] = N.nan
     one_hit = N.logical_xor(*bottom_hem)
     select[one_hit] = N.nonzero(bottom_hem[:,one_hit])[0]
     
     return select
示例#10
0
    def _select_coords(self, coords, prm):
        """
        Select from dual intersections by vetting out rays in the upper
        hemisphere, or if both are below use the default behaviour of choosing
        the first hit.
        """
        select = QuadricGM._select_coords(self, coords, prm)  # defaults

        coords = N.concatenate((coords, N.ones((2, 1, coords.shape[2]))),
                               axis=1)
        local = N.sum(N.linalg.inv(self._working_frame)[None,:,:,None] * \
            coords[:,None,:,:], axis=2)
        bottom_hem = (local[:, 2, :] <= 0) & (prm > 1e-6)

        select[~N.logical_or(*bottom_hem)] = N.nan
        one_hit = N.logical_xor(*bottom_hem)
        select[one_hit] = N.nonzero(bottom_hem[:, one_hit])[0]

        return select