Build a torus of specified outer radius `r` internal radius `thickness`, centered at `pos`.

    .. hint:: |gas| |gas.py|_
518083
def Torus(pos=(0, 0, 0), r=1, thickness=0.1, axis=(0, 0, 1), c="khaki", alpha=1, res=30):
    
    rs = vtk.vtkParametricTorus()
    rs.SetRingRadius(r)
    rs.SetCrossSectionRadius(thickness)
    pfs = vtk.vtkParametricFunctionSource()
    pfs.SetParametricFunction(rs)
    pfs.SetUResolution(res * 3)
    pfs.SetVResolution(res)
    pfs.Update()

    nax = np.linalg.norm(axis)
    if nax:
        axis = np.array(axis) / nax
    theta = np.arccos(axis[2])
    phi = np.arctan2(axis[1], axis[0])
    t = vtk.vtkTransform()
    t.PostMultiply()
    t.RotateY(theta * 57.3)
    t.RotateZ(phi * 57.3)
    tf = vtk.vtkTransformPolyDataFilter()
    tf.SetInputData(pfs.GetOutput())
    tf.SetTransform(t)
    tf.Update()
    pd = tf.GetOutput()

    actor = Actor(pd, c, alpha)
    actor.GetProperty().SetInterpolationToPhong()
    actor.SetPosition(pos)
    settings.collectable_actors.append(actor)
    return actor
280347
function ( radius, detail ) {

	var t = ( 1 + Math.sqrt( 5 ) ) / 2;

	var vertices = [
		- 1, t, 0, 	1, t, 0, 	- 1, - t, 0, 	1, - t, 0,
		 0, - 1, t, 	0, 1, t,	0, - 1, - t, 	0, 1, - t,
		 t, 0, - 1, 	t, 0, 1, 	- t, 0, - 1, 	- t, 0, 1
	];

	var indices = [
		 0, 11, 5, 	0, 5, 1, 	0, 1, 7, 	0, 7, 10, 	0, 10, 11,
		 1, 5, 9, 	5, 11, 4,	11, 10, 2,	10, 7, 6,	7, 1, 8,
		 3, 9, 4, 	3, 4, 2,	3, 2, 6,	3, 6, 8,	3, 8, 9,
		 4, 9, 5, 	2, 4, 11,	6, 2, 10,	8, 6, 7,	9, 8, 1
	];

	PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );

	this.type = '';

	this.parameters = {
		radius: radius,
		detail: detail
	};

}
95251
def radius_cmp(a, b, offsets):
    ''''''
    diff = radius(a, offsets) - radius(b, offsets)
    if diff > 0:
        return 1
    if diff < 0:
        return -1
    return 0
966739
def optimise_z(z, *args):
    """"""
    x, y, elements, coordinates = args
    window_com = np.array([x, y, z])
    return pore_diameter(elements, coordinates, com=window_com)[0]
378267
def _build_rhs(p, q, deriv):
    """"""

    b = [0 for _ in range(p+q+1)]
    b[deriv] = math.factorial(deriv)
    return np.array(b)
289252
def pickAChannel(self, ra_deg, dec_deg):
        
        # Could improve speed by doing this in the projection plane
        # instead of sky coords
        cRa = self.currentRaDec[:, 3]  # Ra of each channel corner
        cDec = self.currentRaDec[:, 4]  # dec of each channel corner

        dist = cRa * 0
        for i in range(len(dist)):
            dist[i] = gcircle.sphericalAngSep(cRa[i], cDec[i], ra_deg, dec_deg)

        i = np.argmin(dist)
        return self.currentRaDec[i, 2]
469554
def ring(x, y, height, thickness, gaussian_width):
    
    radius = height/2.0
    half_thickness = thickness/2.0

    distance_from_origin = np.sqrt(x**2+y**2)
    distance_outside_outer_disk = distance_from_origin - radius - half_thickness
    distance_inside_inner_disk = radius - half_thickness - distance_from_origin

    ring = 1.0-np.bitwise_xor(np.greater_equal(distance_inside_inner_disk,0.0),
                              np.greater_equal(distance_outside_outer_disk,0.0))

    sigmasq = gaussian_width*gaussian_width

    if sigmasq==0.0:
        inner_falloff = x*0.0
        outer_falloff = x*0.0
    else:
        with float_error_ignore():
            inner_falloff = np.exp(np.divide(-distance_inside_inner_disk*distance_inside_inner_disk, 2.0*sigmasq))
            outer_falloff = np.exp(np.divide(-distance_outside_outer_disk*distance_outside_outer_disk, 2.0*sigmasq))

    return np.maximum(inner_falloff,np.maximum(outer_falloff,ring))
1329471
def coord_grid(self):
        """"""

        import math,ephem
        ra2=math.pi*2
        ra1=0
        dec1=-1*math.pi/2.0
        dec2=math.pi/2.0

        
        ## grid space choices
        ## ra space in hours
        ra_grids=["06:00:00",
                  "03:00:00",
                  "01:00:00",
                  "00:30:00",
                  "00:15:00",
                  "00:05:00",
                  "00:01:00",
                  "00:00:30",
                  "00:00:15",
                  "00:00:05"]
        dec_grids=["45:00:00",
                   "30:00:00",
                   "15:00:00",
                   "05:00:00",
                   "01:00:00",
                   "00:15:00",
                   "00:05:00",
                   "00:01:00",
                   "00:00:30"]
        dra=(self.x2-self.x1)/3.0
        ddec=(self.y2-self.y1)/3.0
        for ra_grid in ra_grids:
            if self.hours(ra_grid)<math.fabs(dra):
                break
        ra_grid=self.hours(ra_grid)

        for dec_grid in dec_grids:
            if self.degrees(dec_grid)<math.fabs(ddec):
                break
        dec_grid=self.degrees(dec_grid)
        
        ra=ra1
        n=0
        import Tkinter,ephem
        while (ra<=ra2):
            (cx1,cy1)=self.p2c((ra,dec1))
            ly=cy1-30
            (cx2,cy2)=self.p2c((ra,dec2))
            self.create_line(cx1,cy1,cx2,cy2)
            lx=cx1
            n=n+1
            if n==2:
                dec=dec1
                k=2
                while ( dec <= dec2 ):
                    (lx,ly)=self.p2c((ra,dec))
                    (cx1,cy1)=self.p2c((ra1,dec))
                    (cx2,cy2)=self.p2c((ra2,dec))
                    self.create_line(cx1,cy1,cx2,cy2)
                    k=k+1
                    if k==3:
                        self.create_text(lx-45,ly-12,text=str(ephem.hours(ra)),fill='green')
                        self.create_text(lx+40,ly-12,text=str(ephem.degrees(dec)),fill='brown')
                        self.create_point(ra,dec,color='black',size=3)
                        k=0
                    dec=dec+dec_grid
                n=0
            ra=ra+ra_grid
1078747
def pseudo_core_density(self):
        """"""
        mesh, values, attrib = self._parse_radfunc("pseudo_core_density")
        return RadialFunction(mesh, values)
1163572
def _make_annulus_path(patch_inner, patch_outer):
        

        import matplotlib.path as mpath

        path_inner = patch_inner.get_path()
        transform_inner = patch_inner.get_transform()
        path_inner = transform_inner.transform_path(path_inner)

        path_outer = patch_outer.get_path()
        transform_outer = patch_outer.get_transform()
        path_outer = transform_outer.transform_path(path_outer)

        verts_inner = path_inner.vertices[:-1][::-1]
        verts_inner = np.concatenate((verts_inner, [verts_inner[-1]]))

        verts = np.vstack((path_outer.vertices, verts_inner))
        codes = np.hstack((path_outer.codes, path_inner.codes))

        return mpath.Path(verts, codes)
1178209
def RadiusGrid(gridSize):
    
    x,y=np.mgrid[0:gridSize,0:gridSize]
    x = x-(gridSize-1.0)/2.0
    y = y-(gridSize-1.0)/2.0
    return np.abs(x+1j*y)
638661
function(a,b,c) {
		var opts = {
			mesh: undefined,
			steps: 12,
			thetaOffset: 0
		};
		if(arguments.length == 1 && typeof arguments[0] == 'object'){ //options object
			for(var prop in arguments[0]){
				opts[prop] = arguments[0][prop];
			}
		} else if(arguments.length == 2){
			opts.steps = arguments[0];
			opts.thetaOffset = arguments[1];
		}
		var cone = new Cone(this.pos,this.getMajorAxis().getVector(), this.radius, this.radius, this.length);
		return cone.toMesh(opts.mesh,opts.steps,opts.thetaOffset,true,true);
	}
230124
function generateArcPath (x, y, radius, startAngle, endAngle) {
  var start = polarToCartesian(x, y, radius, startAngle);
  var end = polarToCartesian(x, y, radius, endAngle);
  var arcSweep = endAngle - startAngle <= 180 ? '0' : '1';
  return [
    'M', start.x, start.y,
    'A', radius, radius, 0, arcSweep, 0, end.x, end.y
  ].join(' ');
}
418132
def bottom(self, z=0, radius=0, degrees=0, reference=None):
        
        coordinates = self.from_center(
            r=radius,
            theta=(degrees / 180) * math.pi,
            h=-1,
            reference=reference)
        return (self, coordinates + (0, 0, z))
368476
def plot_sphere(ax, center, radius, color='black', alpha=1., linspace_count=_LINSPACE_COUNT):
    

    u = np.linspace(0, 2 * np.pi, linspace_count)
    v = np.linspace(0, np.pi, linspace_count)
    sin_v = np.sin(v)
    x = center[0] + radius * np.outer(np.cos(u), sin_v)
    y = center[1] + radius * np.outer(np.sin(u), sin_v)
    z = center[2] + radius * np.outer(np.ones_like(u), np.cos(v))

    ax.plot_surface(x, y, z, linewidth=0.0, color=color, alpha=alpha)
827351
function ( radius, tube, radialSegments, tubularSegments, arc ) {

	BufferGeometry.call( this );

	this.type = '';

	this.parameters = {
		radius: radius,
		tube: tube,
		radialSegments: radialSegments,
		tubularSegments: tubularSegments,
		arc: arc
	};

	radius = radius || 1;
	tube = tube || 0.4;
	radialSegments = Math.floor( radialSegments ) || 8;
	tubularSegments = Math.floor( tubularSegments ) || 6;
	arc = arc || Math.PI * 2;

	// buffers

	var indices = [];
	var vertices = [];
	var normals = [];
	var uvs = [];

	// helper variables

	var center = new Vector3();
	var vertex = new Vector3();
	var normal = new Vector3();

	var j, i;

	// generate vertices, normals and uvs

	for ( j = 0; j <= radialSegments; j ++ ) {

		for ( i = 0; i <= tubularSegments; i ++ ) {

			var u = i / tubularSegments * arc;
			var v = j / radialSegments * Math.PI * 2;

			// vertex

			vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
			vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
			vertex.z = tube * Math.sin( v );

			vertices.push( vertex.x, vertex.y, vertex.z );

			// normal

			center.x = radius * Math.cos( u );
			center.y = radius * Math.sin( u );
			normal.subVectors( vertex, center ).normalize();

			normals.push( normal.x, normal.y, normal.z );

			// uv

			uvs.push( i / tubularSegments );
			uvs.push( j / radialSegments );

		}

	}

	// generate indices

	for ( j = 1; j <= radialSegments; j ++ ) {

		for ( i = 1; i <= tubularSegments; i ++ ) {

			// indices

			var a = ( tubularSegments + 1 ) * j + i - 1;
			var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
			var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
			var d = ( tubularSegments + 1 ) * j + i;

			// faces

			indices.push( a, b, d );
			indices.push( b, c, d );

		}

	}

	// build geometry

	this.setIndex( indices );
	this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
	this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
	this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );

}
1210417
def fixed_point_density_preserving(points, cells, *args, **kwargs):
    

    def get_new_points(mesh):
        # Get circumcenters everywhere except at cells adjacent to the boundary;
        # barycenters there.
        cc = mesh.cell_circumcenters
        bc = mesh.cell_barycenters
        # Find all cells with a boundary edge
        boundary_cell_ids = mesh.edges_cells[1][:, 0]
        cc[boundary_cell_ids] = bc[boundary_cell_ids]
        return get_new_points_count_averaged(mesh, cc)

    mesh = MeshTri(points, cells)
    runner(get_new_points, mesh, *args, **kwargs)
    return mesh.node_coords, mesh.cells["nodes"]