top of page

Convert cylindrical to cartesian coordinates

  • Peter Mortier
  • Mar 30
  • 3 min read

Updated: 1 day ago

In this example, you will learn how to use a coordinate transformation to create a cylindrical 3D model. The transformation that we will use is to convert cylindrical to Cartesian coordinates. Cylindrical coordinates, defined by radius, polar angle, and height, are ideal for representing cylindrical objects.


We will generate a tube with holes, which could for example be manufactured through laser cutting. The resulting mesh consist of hexahedral elements, and both the geometry as well as the mesh density are fully parametric. In other words, by changing the geometrical and mesh parameters at the top of the script, you can quickly generate alternative models. How cool is that :) Check this post on parametric mesh modelling if you want to learn more about this topic


The script below consists of the following steps:

  • First, a planar quadrilateral mesh of the outer tube surface is created. We do this by connecting an arc and a polyline. This results in a mesh representing 1/4 of the basic unit, which is a rectangle with a hole in the middle.

  • The full mesh of the basic unit (= rectangle with hole) is obtained using the rosette method. This method allows to create rotational replications of a mesh.

  • In a next step, we replicate the basic unit along the Y-axis ("no" times), and an important scaling of the model is performed. With this scaling, we match the length of the model in the Y-direction with the circumference of the tube. A uniform scaling in all directions is used so that we will obtain circular holes after the coordinate transformation.

  • With the extrusion, a thickness is given to the quadrilateral mesh, resulting in a hexahedral mesh.

  • The model is translated and scaled in preparation of the coordinate transformation, as explained in the comments.

  • When performing the coordinate transformation, we need to specify which directions in our model correspond with the radial (= direction 2), polar (= direction 1) and the axial (= direction 0) directions. Hence, the argument " dir = (2, 1, 0)" .


As usual, this example is best investigated by visualizing the intermediate steps of the script.


If you are interested in coordinate transformations, you may also want to take a look at our example showing how to convert spherical to cartesian coordinates.


from hellotriangle import shapes
import numpy as np

# dimensions
tt = 0.5 # tube thickness
tr = 3.0 # tube radius

# mesh parameters
nc = 5   # number of elements along 45 degree arc
no = 6   # number of circular holes along circumference
n = 4    # number of elements within unit
nt = 1   # number of elements along tube thickness

# derived tube circumference
tc = 2.0*tr*np.pi

# generate unit with quadrilateral elements
arc = shapes.arc(angle = 90., n = 2*nc)
line = shapes.polyline([[2.0, 0.0, 0.0], [2.0, 2.0, 0.0], [0.0, 2.0, 0.0]], n = nc, closed = False)
unit = arc.connect(line, div = n)

# replicate around Z axis to create a rectangle with a hole
rectWithHole = unit.rosette(n = 4, axis = 2)

# replicate and scale to match the tube circumference
full = rectWithHole.replicate(n = no, dir = [0.0, 1.0, 0.0], step = 4.0).scale(tc/(4*no))

# extrude to generate hex elements
hex = full.extrude(nt, dir = 2, length = tt)

# translate so that the Z-value corresponds to the radius
hex = hex.translate([0.,0.,tr-tt])

# scale so that Y values range between 0-360 (degrees)
hex = hex.scale([1.0, 360.0/tc, 1.0])

# coordinate transformation (from cylindrical coordinates to cartesian)
tube = hex.cylindrical(dir = (2, 1, 0))

# draw
scene.add(tube)
Convert cylindrical to cartesian coordinates
Figure: High quality hexahedral mesh obtained through converting from cylindrical to cartesian coordinates.

Subscribe to our newsletter

Join our email list and get updates about HelloTriangle. Unsubscribe anytime.

Thanks for submitting!

© 2024 by HelloTriangle

  • LinkedIn
bottom of page