Python draw sphere
19 Python code examples are found related to "
draw sphere".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: normal_util.py From deep_human with GNU General Public License v3.0 | 7 votes |
def draw_normal_sphere(batchsize, r): square = -np.ones([2*r, 2*r, 3]) centerx = r centery = r for i in range(2*r): for j in range(2*r): x = (j - centerx) / r y = (i - centery) / r if x**2 + y**2 < 1: z = -math.sqrt(1 - x**2 - y**2) square[i, j, :] = [x, y, z] square = np.expand_dims(square, 0) square = np.repeat(square, batchsize, axis=0) square = transform_normal(square) return square
Example 2
Source File: sphere.py From pyray with MIT License | 6 votes |
def draw_wavy_sphere_acceleration_wrapper(save_dir, number_of_circles, line_thickness): # Create n images (frames) where n = number_of_circles for i in np.arange(number_of_circles): wavy_index = i % number_of_circles if (wavy_index > 0.65*number_of_circles and wavy_index%2!=0): pass else: # 2.52 is an angle of Z axis (Why did I choose 2.52? For aesthetic reasons:)) r = rotation(3, 2.50 + np.pi*np.sin(i/10.0) * np.random.uniform(0.8,1) / 30.0) # Create the canvas size of (500, 500) im = Image.new("RGB", (500, 500), (1, 1, 1)) draw = ImageDraw.Draw(im, 'RGBA') # Sphere's center is np.array([0,0,0]) # The vector that passes through the center is np.array([0,0,1]) # Radius is oscillating randomly draw_sphere2(draw, np.array([0,0,0]), np.array([0,0,1]), 1, r, wavy_index = wavy_index ,num_circle = number_of_circles, rgba=(182, 183, 186, 255), width = line_thickness) file_name = save_dir + str(i) + '.png' im.save(file_name)
Example 3
Source File: wx_viewer.py From dials with BSD 3-Clause "New" or "Revised" License | 6 votes |
def draw_minimum_covering_sphere(self): if self.minimum_covering_sphere_display_list is None: self.minimum_covering_sphere_display_list = gltbx.gl_managed.display_list() self.minimum_covering_sphere_display_list.compile() s = self.minimum_covering_sphere c = s.center() r = s.radius() gray = 0.3 gl.glColor3f(gray, gray, gray) gl.glBegin(gl.GL_POLYGON) for i in range(360): a = i * math.pi / 180 rs = r * math.sin(a) rc = r * math.cos(a) gl.glVertex3f(c[0], c[1] + rs, c[2] + rc) gl.glEnd() self.draw_cross_at(c, color=(1, 0, 0)) self.minimum_covering_sphere_display_list.end() self.minimum_covering_sphere_display_list.call()
Example 4
Source File: sphere.py From pyray with MIT License | 6 votes |
def draw_rotating_sphere(number_of_circles, line_thickness, save_dir=None, is_stream=False): if not is_stream and save_dir is None: raise Exception("Save directory required when not streaming") # Create total 30 images for i in np.arange(30): # We'll rotate the sphere by 18 degrees (18 = pi/10) r = rotation(3, np.pi*i / 100.0) # Create the canvas size of (500, 500) im = Image.new("RGB", (500, 500), (1, 1, 1)) draw = ImageDraw.Draw(im, 'RGBA') draw_sphere(draw, np.array([0,0,0]), np.array([0,0,1]), 1, r, num_circle = number_of_circles, rgba=(182, 183, 186, 255), width = line_thickness) if is_stream: yield get_image_bytes(im) else: file_name = save_dir + str(i) + '.png' im.save(file_name)
Example 5
Source File: sphere.py From pyray with MIT License | 6 votes |
def draw_wavy_sphere_wrapper(save_dir, number_of_circles, line_thickness): # Create n images (frames) where n = number_of_circles for i in np.arange(number_of_circles): wavy_index = i % number_of_circles # 2.52 is an angle of Z axis (Why do I choose 2.52? For an aesthetic reason:)) r = rotation(3, 2.50 + np.pi*np.sin(i/10.0) * np.random.uniform(0.8,1) / 30.0) # Create the canvas size of (500, 500) im = Image.new("RGB", (500, 500), (1, 1, 1)) draw = ImageDraw.Draw(im, 'RGBA') # Sphere's center is np.array([0,0,0]) # The vector that passes through the center is np.array([0,0,1]) # Radius is oscillating randomly draw_sphere(draw, np.array([0,0,0]), np.array([0,0,1]), 1, r, wavy_index = wavy_index ,num_circle = number_of_circles, rgba=(182, 183, 186, 255), width = line_thickness) file_name = save_dir + str(i) + '.png' im.save(file_name)
Example 6
Source File: sphere.py From pyray with MIT License | 6 votes |
def draw_oscillating_sphere(save_dir, number_of_circles, line_thickness): # Craete total 60 images for i in np.arange(60): # 2.5 is an angle of Z axis # pi * sin(k) is an oscillating factor r = rotation(3, 2.5 + np.pi*np.sin(i/10.0) * np.random.uniform(0.75,1) / 20.0) # Create the canvas size of (500, 500) im = Image.new("RGB", (500, 500), (1, 1, 1)) draw = ImageDraw.Draw(im, 'RGBA') # Sphere's center is np.array([0,0,0]) # The vector that passes through the center is np.array([0,0,1]) # Radius is oscillating randomly: 1 * np.random.uniform(0.75,1) + 0.4 * np.sin(np.pi/10.0*i) draw_sphere(draw, np.array([0,0,0]), np.array([0,0,1]), 1 * np.random.uniform(0.75,1) + 0.4 * np.sin(np.pi/10.0*i), r, num_circle = number_of_circles, rgba=(182, 183, 186, 255), width = line_thickness) file_name = save_dir + str(i) + '.png' im.save(file_name)
Example 7
Source File: draw_gauss_ball.py From vmf_vae_nlp with MIT License | 6 votes |
def drawSphere(xCenter, yCenter, zCenter, r): # draw sphere u, v = np.mgrid[0:2 * np.pi:20j, 0:np.pi:10j] x = np.cos(u) * np.sin(v) y = np.sin(u) * np.sin(v) z = np.cos(v) # shift and scale sphere x = r * x + xCenter y = r * y + yCenter z = r * z + zCenter return (x, y, z)
Example 8
Source File: drawSphere.py From BlenderToolbox with Apache License 2.0 | 6 votes |
def drawSphere(ptSize, ptColor, ptLoc = (1e10,1e10,1e10)): bpy.ops.mesh.primitive_uv_sphere_add(radius = ptSize) sphere = bpy.context.object sphere.location = ptLoc bpy.ops.object.shade_smooth() mat = bpy.data.materials.new('sphere_mat') sphere.data.materials.append(mat) mat.use_nodes = True tree = mat.node_tree BCNode = initColorNode(tree, ptColor) tree.nodes["Principled BSDF"].inputs['Roughness'].default_value = 1.0 tree.nodes["Principled BSDF"].inputs['Sheen Tint'].default_value = 0 tree.links.new(BCNode.outputs['Color'], tree.nodes['Principled BSDF'].inputs['Base Color']) return sphere
Example 9
Source File: minecraftstuff.py From TeachCraft-Examples with MIT License | 5 votes |
def drawSphere(self, x1, y1, z1, radius, blockType, blockData=0): """ draws a sphere around a point to a radius :param int x1: The x position of the centre of the sphere. :param int y1: The y position of the centre of the sphere. :param int z1: The z position of the centre of the sphere. :param int radius: The radius of the sphere. :param int blockType: The block id. :param int blockData: The block data value, defaults to ``0``. """ for x in range(radius * -1, radius): for y in range(radius * -1, radius): for z in range(radius * -1, radius): if x**2 + y**2 + z**2 < radius**2: self.drawPoint3d(x1 + x, y1 + y, z1 + z, blockType, blockData)
Example 10
Source File: minecraftstuff.py From TeachCraft-Examples with MIT License | 5 votes |
def drawHollowSphere(self, x1, y1, z1, radius, blockType, blockData=0): """ draws a hollow sphere around a point to a radius, sphere has to big enough to be hollow! :param int x1: The x position of the centre of the sphere. :param int y1: The y position of the centre of the sphere. :param int z1: The z position of the centre of the sphere. :param int radius: The radius of the sphere. :param int blockType: The block id. :param int blockData: The block data value, defaults to ``0``. """ for x in range(radius * -1, radius): for y in range(radius * -1, radius): for z in range(radius * -1, radius): if (x**2 + y**2 + z**2 < radius**2) and (x**2 + y**2 + z**2 > (radius**2 - (radius * 2))): self.drawPoint3d(x1 + x, y1 + y, z1 +z, blockType, blockData)
Example 11
Source File: minecraftstuff.py From JuicyRaspberryPie with BSD 2-Clause "Simplified" License | 5 votes |
def drawHollowSphere(self, x1, y1, z1, radius, blockType): """ draws a hollow sphere around a point to a radius, sphere has to big enough to be hollow! :param int x1: The x position of the centre of the sphere. :param int y1: The y position of the centre of the sphere. :param int z1: The z position of the centre of the sphere. :param int radius: The radius of the sphere. :param int blockType: The block id. :param int blockData: The block data value, defaults to ``0``. """ for x in range(radius * -1, radius): for y in range(radius * -1, radius): for z in range(radius * -1, radius): if (x**2 + y**2 + z**2 < radius**2) and (x**2 + y**2 + z**2 > (radius**2 - (radius * 2))): self.drawPoint3d(x1 + x, y1 + y, z1 +z, blockType)
Example 12
Source File: minecraftstuff.py From JuicyRaspberryPie with BSD 2-Clause "Simplified" License | 5 votes |
def drawSphere(self, x1, y1, z1, radius, blockType): """ draws a sphere around a point to a radius :param int x1: The x position of the centre of the sphere. :param int y1: The y position of the centre of the sphere. :param int z1: The z position of the centre of the sphere. :param int radius: The radius of the sphere. :param int blockType: The block id. :param int blockData: The block data value, defaults to ``0``. """ for x in range(radius * -1, radius): for y in range(radius * -1, radius): for z in range(radius * -1, radius): if x**2 + y**2 + z**2 < radius**2: self.drawPoint3d(x1 + x, y1 + y, z1 + z, blockType)
Example 13
Source File: sphere.py From pyray with MIT License | 5 votes |
def draw_goldberg_sphere(): faces = np.array([[sphere_vertices[j] for j in i] for i in sphere_faces]) for i in range(30): im = Image.new("RGB", (2048, 2048), (1, 1, 1)) draw = ImageDraw.Draw(im, 'RGBA') r = general_rotation(np.array([1,0,0]), 2*np.pi/30*i) render_solid_planes(faces, draw, r) im.save('im' + str(i) + '.png')
Example 14
Source File: minecraftstuff.py From minecraft-starwars with MIT License | 5 votes |
def drawHollowSphere(self, x1, y1, z1, radius, blockType, blockData=0): # create sphere for x in range(radius*-1,radius): for y in range(radius*-1, radius): for z in range(radius*-1,radius): if (x**2 + y**2 + z**2 < radius**2) and (x**2 + y**2 + z**2 > (radius**2 - (radius * 2))): self.drawPoint3d(x1 + x, y1 + y, z1 +z, blockType, blockData) # draw a verticle circle
Example 15
Source File: geometry_viewer.py From notebook-molecular-visualization with Apache License 2.0 | 5 votes |
def draw_sphere(self, center, radius=2.0, color='red', opacity=1.0): """ Draw a 3D sphere into the scene Args: center (Vector[length, len=3]): center of the sphere radius (Scalar[length]): radius of the sphere color (str or int): color name or RGB hexadecimal opacity (float): sphere opacity Returns: dict: sphere spec object """ center = self._convert_length(center) radius = self._convert_length(radius) color = translate_color(color) shape = { 'type': self.SHAPE_NAMES['SPHERE'], 'center': self._list_to_jsvec(center), 'radius': radius, 'color': color, 'opacity': opacity, } shapes = list(self.shapes) shapes.append(shape) self.shapes = shapes self._update_clipping(center.max() + radius) return shape
Example 16
Source File: minecraftstuff.py From minecraft-starwars with MIT License | 5 votes |
def drawSphere(self, x1, y1, z1, radius, blockType, blockData=0): # create sphere for x in range(radius*-1,radius): for y in range(radius*-1, radius): for z in range(radius*-1,radius): if x**2 + y**2 + z**2 < radius**2: self.drawPoint3d(x1 + x, y1 + y, z1 + z, blockType, blockData) # draw hollow sphere
Example 17
Source File: np_image.py From MedicalDataAugmentationTool with GNU General Public License v3.0 | 5 votes |
def draw_sphere(image, center, radius, value=1): z, y, x = np.meshgrid(range(image.shape[0]), range(image.shape[1]), range(image.shape[2]), indexing='ij') d = np.sqrt((z - center[0]) ** 2 + (y - center[1]) ** 2 + (x - center[2]) ** 2) image[d <= radius] = value return image
Example 18
Source File: collider.py From BlenderTools with GNU General Public License v2.0 | 5 votes |
def draw_shape_sphere(mat, obj_scs_props, scs_globals): """Draw sphere collider. :param mat: Object matrix 4x4 :type mat: Matrix :param obj_scs_props: SCS Object properties :type obj_scs_props: prop :param scs_globals: global settings :type scs_globals: prop """ if obj_scs_props.locator_collider_centered: shift = 0.0 else: shift = -obj_scs_props.locator_collider_dia / 2 mat1 = mat @ Matrix.Translation((0.0, shift, 0.0)) @ Matrix.Scale(obj_scs_props.locator_collider_dia, 4) sphere_vertices, sphere_faces, sphere_wire_lines = _primitive.get_sphere_data() _primitive.draw_polygon_object(mat1, sphere_vertices, sphere_faces, scs_globals.locator_coll_face_color, obj_scs_props.locator_collider_faces, obj_scs_props.locator_collider_wires, wire_lines=sphere_wire_lines, wire_color=scs_globals.locator_coll_wire_color)
Example 19
Source File: a2plib.py From A2plus with GNU Lesser General Public License v2.1 | 5 votes |
def drawSphere(center, color): doc = FreeCAD.ActiveDocument s = Part.makeSphere(2.0,center) sphere = doc.addObject("Part::Feature","Sphere") sphere.Shape = s sphere.ViewObject.ShapeColor = color doc.recompute() #------------------------------------------------------------------------------