17

I'm after an adjustable pie chart. Think of a circular box of cheese triangles. Each triangle is a separate object from the others (and variable in the .pct of the circle, but together form a thick disk - like a hockey puck.

NeverGiveUp
  • 701
  • 1
  • 12
  • 23
  • By variable/adjustable do you mean set some values in a script then run it to generate the pie chart? Or do you mean that the values are adjustable in real time after the pie chart has been generated? Big difference. – Todd McIntosh Jul 28 '15 at 17:16
  • a script would be terrific, but way beyond my capabilities. The .blend file would be a template for reuse, with new data for the .pcts. It's important that the "wedges" be separate objects. Tks. – NeverGiveUp Jul 28 '15 at 17:48
  • 1
    Related answer: http://blender.stackexchange.com/questions/7283/how-to-create-a-pacman-esque-clock-icon – Paul Gonet Jul 28 '15 at 18:16

6 Answers6

21

You can also do this with a curve by adding a bevel object and changing the Start/End values of the bevel:

enter image description here

  1. Shift+A> Curve> Circle.

  2. In edit mode of the new curve press Alt+C to 'Toggle Cyclic' so the curve doesn't join its ends together:

enter image description here

  1. Select all the curve points and change their handle type to 'Free' in the side toolbar (T) under 'Handles' and move the curve points back into a circular shape (but the circle will now have a gap).

  2. Extrude the last curve point with E and place it exactly on top of the other end of the curve (a bit more carefully than I have):

enter image description here

  1. Now add a new curve in object mode and flatten it so it is a straight line:

enter image description here

  1. In the curve properties for the curve that is a circle set the 'Bevel Object' to be the curve that is a straight line:

enter image description here

  1. You can now adjust the 'Start' or 'End' values (shown in the first gif) to adjust the 'completeness' of the circle.

  2. As one final step, you can give thickness to the curve by adding a 'Solidify' modifier and then an 'Edge split' modifier to correct the shading:

enter image description here

Duplicate this curve and adjust the 'Start' and 'End' values for each new segment of the pie.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
  • 2nd step 3. How do I flatten the curve? – NeverGiveUp Jul 28 '15 at 20:26
  • It will depend on which axis the curve gets added on, but select both curve points and then press either S,X,0 or S,Y,0 or S,Z,0. See http://blender.stackexchange.com/questions/140/how-to-align-a-cluster-of-points/156?s=0|0.1857#156 – Ray Mairlot Jul 28 '15 at 20:40
  • so 1 "wedge" is done, now how do I add the next one so it fits in the pie? – NeverGiveUp Jul 28 '15 at 22:03
  • You should be able to duplicate the wedge with Shift+D, rotate it with R,Z, then alter the 'Start' value to resize it. – Ray Mairlot Jul 28 '15 at 22:38
  • Tedious, but works great. Learned a lot! There should be an add on that does this by filling in .pcts, thickness, etc.. – NeverGiveUp Jul 29 '15 at 22:58
  • @NeverGiveUp - in edit mode select both points, press V and choose vector, this will point both handles at each other giving a straight line. – sambler Jul 30 '15 at 06:28
  • Fantastic approach, much learned. – faybn Dec 11 '19 at 10:47
13

One could use Sverchok - node based parametric geometry addon. (Full disclosure, I co-write this addon - but it is free and open-source)

enter image description here

All you then do is change the values in the List Input node..

enter image description here

And set the materials..

enter image description here

Here an alternative with some of the sliders labeled to help you out.

enter image description here


Pros and Cons to doing this:

Cons

  • You have to install Sverchok Add-on
  • Making it fully reusable requires a bit of coding or node noodling
  • Sverchok doesn't have a functioning List Running Sum operator, the code exists but we never committed it. Questions like this reinforce why the extra operator should be added (thanks!)
  • I've not written an example of how to dynamically pick n new colours when the amount of list items is updated.

Pros

  • You get to experiment with Sverchok, and accidents lead to learning and the add-on has many more uses.
  • You can easily develop parametric tools (node trees) that can be every bit as good as an addon, but with often less setup code.

Here's a version that does create new random colors for new list items, this might be handy during the construction phase to help you see the individual slices, simply disconnect the input to the node once you have enough slices

enter image description here

The script inside the "maker_material" node looks like this, and makes only one assumption; the base name of the object (here Alpha - a default name)

import random
import bpy

def sv_main(num_slices=0):
    dummy = []

    in_sockets = [
        ['s', 'num_slices', num_slices]
    ]

    prefix_name = "Alpha"

    if num_slices and (num_slices > 0):
        for s in range(num_slices):
            obj = bpy.data.objects.get(prefix_name + "_" + str(s))
            if obj:
                materials = obj.data.materials
                if None in materials[:] or len(materials) == 0:
                    print('has no colours! - adding!')

                    mat = bpy.data.materials.new('some_mat')
                    mat.use_nodes = True
                    nodes = mat.node_tree.nodes

                    obj.active_material = mat
                    diffuse = nodes.get("Diffuse BSDF")
                    diffuse.inputs['Color'].default_value = random.random(), random.random(), random.random(), 1.0
                else:
                    print(obj.data.materials[:])

    out_sockets = [
        ['s', 'dummy_out', dummy]
    ]

    return in_sockets, out_sockets
zeffii
  • 39,634
  • 9
  • 103
  • 186
  • The proportion variable aspect (list input) of this is good. It would be great to have a dedicated pie chart add on, but this does not to answer my needs: no hole in center, individual objects for each portion, thickness variability. – NeverGiveUp Jul 29 '15 at 13:14
  • they are separate Mesh Objects, 2) The hole in the middle is because I've translated the output of the Plane Node in the Y direction 3) thickness was never mentioned.. but I could make a quick version
  • – zeffii Jul 29 '15 at 13:25
  • code/scripts, beyond my abilities at the moment. Not for me at this time, Tried to dl add-on w/o success, but many thanks for your efforts. – NeverGiveUp Jul 29 '15 at 17:53
  • That's OK, plenty of other good options here! – zeffii Jul 29 '15 at 18:06