1
$\begingroup$

In general, I'm wondering how to cut a pie slice out of a cylinder. I have done an extensive search and I'm sure it's not that difficult, but I haven't managed to find anything I could apply (possibly because of my novice status in Blender.)

For the moment, my more immediate need is to cut out part of an octogonal prism. So, consider the octogon built with the following code:

import bpy

# Create a 3D octogonal prism.

myRadius = 2.0
myDepth  = 1.0

bpy.ops.mesh.primitive_cylinder_add(
        vertices = 8, radius = myRadius, depth = myDepth,
        location = ( 0, 0, 0 ) ) # location could be other, using origin for simplicity here
bpy.context.object.name  = "myOctogon"

Ultimately, what I want is to end up with is 7/8 of the original prism rotated clockwise by pi/8 so that the gap faces "northeast".

UPDATE: I have discovered that I can do it as follows, though I don't know how to script it all:

import bpy
from math import pi

# Create a 2D octogon.

myRadius = 2.0
myDepth  = 1.0

bpy.ops.mesh.primitive_circle_add(
    vertices = 8 , radius = myRadius,
    fill_type='TRIFAN', 
    location = ( 0, 0, 0 ),
    rotation = ( 0, 0, pi / 8 ) )

bpy.ops.object.editmode_toggle()

# Select the 'northeast' edge.
bpy.ops.mesh.subdivide()

# Select the new vertex, move it to ( 0, 0, 0 ).

# Select the whole 'pac man' shape, extrude to desired height.
bpy.ops.mesh.extrude_region_move( ... ) # need to work out appropriate details
$\endgroup$
5
  • 2
    $\begingroup$ Related blender.stackexchange.com/questions/101446/… blender.stackexchange.com/questions/34685/… blender.stackexchange.com/questions/84372/… To create as a mesh would use create a profile and spin, in this case seven eighths of 360 degrees. To animate look at creating the modifiers (potentially one all or any of spin /solidify array) with code. Answer below shows how to add solidify mod. $\endgroup$
    – batFINGER
    May 14, 2021 at 7:38
  • $\begingroup$ eg spin a single x axis aligned edge around Z and solidify in Z makes a wedge, array makes copies._ $\endgroup$
    – batFINGER
    May 14, 2021 at 7:45
  • $\begingroup$ Thanks, the first two of these I'd seen after posting, wasn't sure how to adapt them to my purpose but it was getting late. Will see what I can manage with it today. I don't want to animate, I'm building a deck ;) $\endgroup$ May 14, 2021 at 14:58
  • $\begingroup$ To do it that way would remove the northeast edge. $\endgroup$
    – batFINGER
    May 14, 2021 at 16:54
  • $\begingroup$ @batFINGER I did it successfully by hand in Blender, so I know it works (my explanation may well be lacking). But no matter. Your solution works for me. $\endgroup$ May 14, 2021 at 17:29

2 Answers 2

2
$\begingroup$

Bmesh version.

  • Make a profile, basically this is just a plane. Have simply made this 1 x 1. Could replace with width and height in x and y respectively (or make a scale matrix)
  • Rotate it about z axis thru origin to some staring point. Rotated such that middle of gap is x = y
  • spin it in 7 eights of 360 degrees in 7 steps.

Test script:

import bpy
import bmesh
from math import pi
from mathutils import Matrix

context = bpy.context
# profile.
coords = (
    (0, 0, 0),
    (1, 0, 0),
    (1, 0, 1),
    (0, 0, 1),
    )
    
bm = bmesh.new()

bm.faces.new(bm.verts.new(co) for co in coords)
bm.transform(Matrix.Rotation(3 * pi / 8, 4, 'Z'))
bmesh.ops.spin(
        bm,
        geom=bm.edges[:] + bm.faces[:],
        axis=(0, 0, 1),
        angle=2 * pi * 7 / 8,
        steps=7,
        )
me = bpy.data.meshes.new("Pie")
bm.to_mesh(me)

ob = bpy.data.objects.new("Pie", me)
context.collection.objects.link(ob)

One edge, with screw and solidify modifiers.

As commented, here is same result with one edge, screwed around then solidified.

import bpy
from mathutils import Matrix
from math import pi
context = bpy.context

verts = (
    (0, 0, 0),
    (1, 0, 0),
    )
    
edges = ((0, 1),)

me = bpy.data.meshes.new("Pie")
me.from_pydata(verts, edges, [])
me.transform(Matrix.Rotation(3 * pi / 8, 4, 'Z'))
ob = bpy.data.objects.new("Pie", me)
screw = ob.modifiers.new("Screw", type='SCREW')
screw.angle = 7 * 2 *  pi / 8
screw.steps = screw.render_steps = 7
screw.use_smooth_shade = False
solidify = ob.modifiers.new("Solidify", type='SOLIDIFY')
solidify.thickness = -1
context.collection.objects.link(ob)

Cut mesh with circle pie chart like mesh for animation

How to create a circle pie chart with separate (adjustable/variable) triangle "chunks"?

Rotated array modifier around constant origin?

$\endgroup$
3
  • $\begingroup$ This works. I ran across the concept 'bmesh' yesterday but have not been able to follow up on it yet; is there a downside to it not just being a 'mesh'? In the interim, I found a way to do it but haven't worked out how to script it all; will add update above. $\endgroup$ May 14, 2021 at 16:23
  • 1
    $\begingroup$ It is simply used to create / edit a mesh. See the API docs. $\endgroup$
    – batFINGER
    May 14, 2021 at 16:47
  • $\begingroup$ I don't understand the details of either solution at the mo but I can work on that! Appreciated. $\endgroup$ May 14, 2021 at 17:20
2
$\begingroup$

Below is a quick and dirty method using a circle and solidify modifier with operators.

import bpy
from math import pi

verts_total = 8
verts_fill = 7
my_radius = 1.0
my_location = (0.0, 0.0, 0.0)
my_rotation = (0.0, 0.0, 0.0)  # use radians
my_depth = 2.0

def make_pacman(verts_total, verts_fill, my_radius, my_location, my_rotation, my_depth):
    # create a circle mesh and create triangle fan fill
    bpy.ops.mesh.primitive_circle_add(
        vertices=verts_total,
        radius=my_radius,
        fill_type='TRIFAN',
        calc_uvs=True,
        location=my_location,
        rotation=my_rotation)

    obj = bpy.context.object
    # add solidify modifier to simulate cylinder
    mod = obj.modifiers.new("SOLIDIFY", type='SOLIDIFY')
    mod.thickness = my_depth 
    mod.offset = 0
    # if full cylinder then done
    if verts_total == verts_fill:
        return
    # select vertices to delete
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_all(action='DESELECT')
    bpy.ops.object.mode_set(mode='OBJECT')
    for i, vert in enumerate(obj.data.vertices):
        if i <= verts_fill:
            continue
        vert.select = True
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.delete(type='VERT')
    bpy.ops.object.mode_set(mode='OBJECT')

make_pacman(verts_total, verts_fill, my_radius, my_location, my_rotation, my_depth)
$\endgroup$
1
  • $\begingroup$ I tried this, but it ends up deleting 1/4 rather than 1/8; I had to run the code step-by-step and then try it manually to see why. Maybe if one moved the 'deleted' point to the centre? Otherwise, maybe I can delete 7/8 and use the remainder as a Boolean and do a difference? $\endgroup$ May 14, 2021 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .