Houdini: Making a circle with code



In Houdini

Knowing where to start to create geometry with code can be daunting. This post hopes to put you on the right path to doing so. You will learn:

  • How to define a circle with maths.

  • How to create a cicle of points with code

As always if you want the TLDR (too long didn’t read) skip to the end for the code snippet and a files.

How to define a circle with math?

Circle cos sin

In the simplest of terms, a circle is just two trigonometry functions (sine and cosine) applied separately to two parameters ( x and y). I think the image to the right best illustrates this.

With some value Θ (which means ‘angle in radians’) the x-axis is determined with sin(Θ) and the y-axis is determined with cos(Θ).

If this is still tough to understand, do not worry, it can take some time to understand but my hope if this image and explanation at least gives you a sense of one way the maths of a circle work.

How to create a circle with code


For our code demonstration, I am using Houdini and its VEX language but this can be used in many other places with some changes. The following snippet will create a circle of 36 points.

int segments = 36;
float step = radians(360)/segments;

for (int i=0; i<segments; i++) {
    float x = sin(step*i);
    float y = cos(step*i);
    vector pos = set(x,y,0);
    addpoint(geoself(), pos);