# Twist during sweep along helix curve

New Cubit user here. I am trying to sweep a rectangle along a helix curve. When I use the native helix from Cubit, it works as expected. However, when I define my own custom helix I am seeing a twisting effect and it does not mesh well. I read the “Twisting During Sweep Along Closed Curve” thread but the discussion was a little above my head at this point, so I cannot be sure if it applies or not.

Thanks

Here is the script I am using:

import numpy as np
import scipy.constants as sc
cubit.cmd(‘reset’)
pie = np.pi/180

# Input parameters

sense = ‘r’ # r or l right or left handed helix
f = 1.8e9 # Frequency Hz
N = 3 # Number of turns
w = 0.1 # Wire diameter, inches
R_gp = 3 # Ground plane radius, inches
alpha_i = 4pie # Starting pitch angle, degrees
alpha_f = 15
pie # Ending pitch angle, degrees

# Compute helix x,y,z points

c = sc.speed_of_light
lamda = c / f * 39.37
C = lamda # Helix circumference
R = C / (2np.pi) # Helix radius
th_max = 2
Nnp.pi
theta = np.linspace(0, th_max, 36
N) # 36 points per turn
x = Rnp.sin(theta)
if sense == ‘r’:
y = -R
np.cos(theta)
else:
y = Rnp.cos(theta)
alpha_m = (alpha_f - alpha_i) / (2
np.piN)
z = R
theta*np.tan(alpha_i + alpha_m * theta)

# Create helix curve

vertexIDs =
for ii in range(0, len(z)):
cubit.cmd(‘create vertex {0} {1} {2}’.format(x[ii], y[ii], z[ii]))
vertexIDs.append(cubit.get_last_id(‘vertex’))
cubit.cmd(‘create curve spline vertex {0} delete’.format(’ '.join(str(vid) for vid in vertexIDs)))
curve_ID = cubit.get_last_id(‘curve’)

# Sweep surface along helix curve

cubit.cmd(‘create surface rectangle width {} xplane’.format(w))
wire_surf_ID = cubit.get_last_id(‘surface’)
cubit.cmd(‘move surface {} x 0 y {} z 0 include_merged’.format(wire_surf_ID, -R))
cubit.cmd(‘sweep surface {} along curve {} to {} keep individual’.format(wire_surf_ID, 1, curve_ID))

Hi @thanos,
could you please post your code again using the quote for code

Just to be sure, you want to use your helix curve to sweep the surface, but it should not start twisting along the curve, like in the helix below.

``````reset
create surface rectangle width 1 height 1 zplane
move Surface 1 x 10 include_merged
sweep surface 1  helix yaxis thread_distance 10 angle 900 right_handed  keep
``````

Hi @Norbert_Hofbauer,
Yes, that is correct. I would like to have my helix look like the one you posted.
Thanks

``````
import numpy as np
import scipy.constants as sc
cubit.cmd('reset')
pie = np.pi/180

# Input parameters

sense = 'r'       # r or l right or left handed helix
f = 1.8e9         # Frequency Hz
N = 3             # Number of turns
w = 0.1           # Wire diameter, inches
R_gp = 3          # Ground plane radius, inches
alpha_i = 4*pie  # Starting pitch angle, degrees
alpha_f = 15*pie  # Ending pitch angle, degrees

# Compute helix x,y,z points

c = sc.speed_of_light
lamda = c / f * 39.37
C = lamda         # Helix circumference
R = C / (2*np.pi) # Helix radius
th_max = 2*N*np.pi
theta = np.linspace(0, th_max, 36*N)  # 36 points per turn
x = R*np.sin(theta)
if sense == 'r':
y = -R*np.cos(theta)
else:
y = R*np.cos(theta)
alpha_m = (alpha_f - alpha_i) / (2*np.pi*N)
z = R*theta*np.tan(alpha_i + alpha_m * theta)

# Create helix curve

vertexIDs = []
for ii in range(0, len(z)):
cubit.cmd('create vertex {0} {1} {2}'.format(x[ii], y[ii], z[ii]))
vertexIDs.append(cubit.get_last_id('vertex'))
cubit.cmd('create curve spline vertex {0} delete'.format(' '.join(str(vid) for vid in vertexIDs)))
curve_ID = cubit.get_last_id('curve')

# Sweep surface along helix curve
cubit.cmd('create surface rectangle width {} xplane'.format(w))
wire_surf_ID = cubit.get_last_id('surface')
cubit.cmd('move surface {} x 0 y {} z 0 include_merged'.format(wire_surf_ID, -R))
cubit.cmd('sweep surface {} along curve {} to {} keep individual'.format(wire_surf_ID, 1, curve_ID))
``````

hi,
i made use of your created vertices and copied the surface along your spline for each vertex. Before moving them to the location on the spline i have rotated them only in the zplane, so they don’t get twisted along the spline anymore. After the creation of the surfaces you can loft a volume.

``````import numpy as np
import scipy.constants as sc
cubit.cmd('reset')
pie = np.pi/180

# Input parameters

sense = 'r'       # r or l right or left handed helix
f = 1.8e9         # Frequency Hz
N = 3             # Number of turns
w = 0.1           # Wire diameter, inches
R_gp = 3          # Ground plane radius, inches
alpha_i = 4*pie  # Starting pitch angle, degrees
alpha_f = 15*pie  # Ending pitch angle, degrees

# Compute helix x,y,z points

c = sc.speed_of_light
lamda = c / f * 39.37
C = lamda         # Helix circumference
R = C / (2*np.pi) # Helix radius
th_max = 2*N*np.pi
theta = np.linspace(0, th_max, 36*N)  # 36 points per turn
x = R*np.sin(theta)
if sense == 'r':
y = -R*np.cos(theta)
else:
y = R*np.cos(theta)
alpha_m = (alpha_f - alpha_i) / (2*np.pi*N)
z = R*theta*np.tan(alpha_i + alpha_m * theta)

# Create helix curve

vertexIDs = []
for ii in range(0, len(z)):
cubit.cmd('create vertex {0} {1} {2}'.format(x[ii], y[ii], z[ii]))
vertexIDs.append(cubit.get_last_id('vertex'))
#cubit.cmd('create curve spline vertex {0} delete'.format(' '.join(str(vid) for vid in vertexIDs)))
cubit.cmd('create curve spline vertex {0} '.format(' '.join(str(vid) for vid in vertexIDs)))
curve_ID = cubit.get_last_id('curve')

# Sweep surface along helix curve
cubit.cmd('create surface rectangle width {} xplane'.format(w))
wire_surf_ID = cubit.get_last_id('surface')
#cubit.cmd('move surface {} x 0 y {} z 0 include_merged'.format(wire_surf_ID, -R))
#cubit.cmd('sweep surface {} along curve {} to {} keep individual'.format(wire_surf_ID, 1, curve_ID))

nv = len(vertexIDs)
curve = cubit.curve(1)
surfaceIDs = []

for i in range(nv):
vertex_id = vertexIDs[i]
vertex = cubit.vertex(vertex_id)
cubit.cmd(f"surface {wire_surf_ID} copy")
surfaceIDs.append(cubit.get_last_id('surface'))
surface = cubit.surface(cubit.get_last_id('surface'))
coord = vertex.coordinates()
tx, ty, tz = curve.tangent(coord)
#print(coord)
#print(tx, ty, tz)
## rotation
a = np.array(tx+0j)
a.imag = np.array([ty])
cubit.cmd(f"rotate surface {surface.id()} angle {np.angle(a, deg=True)} about Z")
cubit.cmd(f"move surface {surface.id()} location vertex {vertex.id()}")

cubit.cmd('create volume loft surface {0} '.format(' '.join(str(sid) for sid in surfaceIDs)))

cubit.cmd('delete surface all with is_free')
cubit.cmd('delete curve all with is_free')
cubit.cmd('delete vertex all with is_free')
``````

After then we can already attempt to mesh.

``````cubit.cmd('compress')
cubit.cmd( f"mesh volume 1" )
``````

To get a better mesh quality i would recommend to make a smooth after meshing here.

``````cubit.cmd( f"volume 1 smooth scheme laplacian free" )
cubit.cmd( f"smooth volume 1" )
``````

That’s a VERY good mesh quality.

Very nice thanks a lot!