I created a program that define some vertices and faces and generate a cylinder in the Blender scene:

import bpy
import math
import mathutils

points = 10
step = ((math.pi* 2) / points)
x = 0
y = 0
current = 0
radius = 0.1
vertices = []
edges = []
faces = []
n_points = 5
n_step = 0
n_dist = 0

for iterator in range(0,n_points):
    for count in range(0,points):

        x = math.sin(current) * radius
        y = math.cos(current) * radius


        current += step

    for count in range(0,points):
        if(iterator >= 1):
            if(count != points-1):
                faces.append((count + iterator*points - points, count + iterator*points+1 - points,  count + iterator*points + 1, count + iterator*points))
                faces.append((count + iterator*points - points, count + iterator*points - (points-1)-points, count + iterator*points - (points-1),count + iterator*points))

    n_step += 0.1

object_mesh = bpy.data.meshes.new("object_mesh")
object_mesh.from_pydata(vertices, edges, faces)
object_object = bpy.data.objects.new("object", object_mesh)
scene = bpy.context.scene 

Following this philosophy I would like to generate a structure that is not just a cylinder but it's a bit more complex and it's shown in the following figure: enter image description here Each of the line in the figure is a circle of points points and they are connected exactly the same way I connected the points in the cylinder with my code. Generating the four sides shouldn't be a big problem but I can't understand how I can generate the oblique circles.
Just to make an example if this code create the upper part of the figure I am achieving, replacing the line vertices.append((0+n_step,x,y)) with vertices.append((0+n_step,x-0.5,y-0.5)) can generate the down part. With some inversions, I think I can generate the side parts but how can I manage the four oblique circles?
Notice that I have to generate the circles in order if I want to add the faces as I am doing now. Of course I am opened to alternatives.

  • $\begingroup$ I may not understand your question. Do you want a single 90 degree rotated circle sharp corner ... or a series smoother circles at corner? Is this a exercise to use Python? Is it true you do not want to model this directly in Blender UI? $\endgroup$ – atomicbezierslinger Aug 10 '17 at 15:49
  • $\begingroup$ If you want to rotate a set of points 45 degrees about some axis, a suggestion is to search here at BSE using a Blender API to provide a matrix to perform rotation. You may have an easy case here, but that may not last for long. $\endgroup$ – atomicbezierslinger Aug 10 '17 at 16:06

A Bmesh take on this. Simplest to add a circle is using Create Circle. The oblique is a circle, scaled by the square root of 2 (Pythagoras) on one axis.

A sample script creates a ring facing front, and an oblique rotated 45, so as that in front ortho view it appears as the circle.

import bpy
import bmesh

from bmesh.types import BMFace as BMFace
from mathutils import Vector, Matrix
from math import radians, sqrt

context = bpy.context

obj = context.object
mesh = bpy.data.meshes.new("Rings")

bm = bmesh.new()
# circle mesh
circle = bmesh.ops.create_circle(bm, diameter=1, segments=10)
# rotate up face front
        cent=(0.0, 0.0, 0.0),
        matrix=Matrix.Rotation(radians(90.0), 3, 'X'))        
# make the oblique circle
oblique = bmesh.ops.create_circle(bm, diameter=1, segments=10)
#scale by root 2
bmesh.ops.scale(bm, vec=(sqrt(2), 1, 1), verts=oblique["verts"])
# rotate up face front
        cent=(0.0, 0.0, 0.0),
        matrix=Matrix.Rotation(radians(90.0), 3, 'X'))        
# and now by 45
        cent=(0.0, 0.0, 0.0),
        matrix=Matrix.Rotation(radians(45.0), 3, 'Z'))   
# feed to the mesh
# do the make object link to scene blah blah
scene = context.scene
ob = bpy.data.objects.new("RingTest", mesh)
scene.objects.active = ob
ob.select = True

enter image description here

  • $\begingroup$ Great answer! I didn't know about the create_circle function. It works exactly as I expected. $\endgroup$ – Rexam Aug 11 '17 at 13:32
  • $\begingroup$ Is there also a way to define and add faces before feeding the mesh? $\endgroup$ – Rexam Aug 12 '17 at 14:30

The following code creates the "oblique circle" that you need in the plane x=z, which, actually, is not a circle but an ellipse (the intersection of two cylinders):

for count in range(0,points):

    x = math.sin(current) * radius
    y = math.cos(current) * radius
    z = math.sin(current) * radius

    vertices.append((x, y, z))
  • $\begingroup$ Intersection of Plane and Cylinder? $\endgroup$ – atomicbezierslinger Aug 10 '17 at 15:15
  • $\begingroup$ Right: the oblique circles are also the intersection of a plane and a cylinder, but with the plane not being orthogonal to the cylinder axis (the angle is 45°). They are also the intersection of two cylinders with orthogonal axis. $\endgroup$ – Regis Portalez Aug 10 '17 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.