Skip to content

Instantly share code, notes, and snippets.

@adhihargo
Created July 23, 2013 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adhihargo/6062845 to your computer and use it in GitHub Desktop.
Save adhihargo/6062845 to your computer and use it in GitHub Desktop.
Add a new quarter curve object.
import bpy
import math
from mathutils import Vector
class OBJECT_OT_quarter_circle(bpy.types.Operator):
"""Create one fourth of a circle."""
bl_idname = 'curve.quarter_circle_add'
bl_label = 'Quarter Circle'
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
curve_name = 'Quarter'
curve = bpy.data.curves.new(curve_name, 'CURVE')
spline = curve.splines.new('BEZIER')
spline.bezier_points.add(count=1)
# http://www.charlespetzold.com/blog/2012/12/Bezier-Circles-and-Bezier-Ellipses.html
handle = 4 * math.tan(math.radians(22.5)) / 3
pt0 = spline.bezier_points[0]
pt0.co = Vector((1.0, 0.0, 0.0))
pt0.handle_right = pt0.co + Vector((0.0, handle, 0.0))
pt0.handle_left = pt0.co
pt1 = spline.bezier_points[1]
pt1.co = Vector((0.0, 1.0, 0.0))
pt1.handle_left = pt1.co + Vector((handle, 0.0, 0.0))
pt1.handle_right = pt1.co
obj = bpy.data.objects.new(curve_name, curve)
context.scene.objects.link(obj)
return {'FINISHED'}
def custom_object_add(self, context):
layout = self.layout
layout.operator("curve.quarter_circle_add", icon='CURVE_BEZCIRCLE')
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_add.append(custom_object_add)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_add.remove(custom_object_add)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment