# How to create an oblique circle of points with Python?

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
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):

vertices.append((0+n_step,x,y))

print("(",x,",",y,")")
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))
else:
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: 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.

• 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? – atomicbezierslinger Aug 10 '17 at 15:49
• 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. – 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

context = bpy.context

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

bm = bmesh.new()
bm.from_mesh(mesh)
# circle mesh
circle = bmesh.ops.create_circle(bm, diameter=1, segments=10)
# rotate up face front
bmesh.ops.rotate(
bm,
verts=circle["verts"],
cent=(0.0, 0.0, 0.0),
# 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
bmesh.ops.rotate(
bm,
verts=oblique["verts"],
cent=(0.0, 0.0, 0.0),
# and now by 45
bmesh.ops.rotate(
bm,
verts=oblique["verts"],
cent=(0.0, 0.0, 0.0),
# feed to the mesh
bm.to_mesh(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 • Great answer! I didn't know about the create_circle function. It works exactly as I expected. – Rexam Aug 11 '17 at 13:32
• Is there also a way to define and add faces before feeding the mesh? – 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):