Parametric Equations: Astroid

(CHOP’s,TOP’s and Python)


In this tutorial we will see how to recreate an Astroid inside Touchdesigner.

Since this curve I’ll cover all the different versions in one post and also I will add the procedure using tops, so feel free to try and experiment with all variations and hope this things help you understand better how to achieve the same goal with differents operator families.

So first a little introduction.

ASTROID

An astroid is a particular mathematical curve: a hypocycloid with four cusps. The parametric equations are:

(a cos3 t,a sin 3 t)

for 0 ≤ t ≤ 2 π

Its modern name comes from the Greek word for “star”. It was proposed, originally in the form of “Astrois”, by Joseph Johann von Littrow in 1838.The curve had a variety of names, including tetracuspid (still used), cubocycloid, and paracycle. It is nearly identical in form to the evolute of an ellipse.

So let’s begin with the fun !

CHOP’s

STEP 1

Create Constant CHOP and declare the parameters we need:

  • Samples = 400
  • a = 1

STEP 2

Create Pattern CHOP and edit the following parameters:

  • Type =  change to Ramp
  • Length = Export samples Parameter from constant1
  • To Range = enter python line math.pi * 2. (Remember we will work with radians as is the most accurate unit for this kind of operations)
  • Channel Name = ‘t’

STEP 3

Then we will connect a function chop to pattern1 and we will change the Function parameter to cos(x) and the unit to radians.

After this we will copy and paste the function chop and in the new copy we will change the function to sin(x)

STEP 4

We will place a math CHOP and we will change the parameter Combine CHOP’s to multiply, and copy paste this operator.

So going back to the parametric equation:

(a cos3 t,a sin 3 t)

We see that the functions are cubed so we need to multiply them three times, and for this the next thing we will do is to connect three times function1 to math1 one and three times function2 to math2.

Finally we merge our math chops to have our functions in one chop.

STEP 5

The last operation of our equations is to multiply our cubed functions by a. So we need to place a select CHOP and drag constant1 to CHOP parameter in the select chop. Then select channel name a.

Then we will connect a math CHOP to merge1, connect select1 to math3 and change the Combine Chop’s parameter on math3 to Multiply.

And we have finished our equations.

The next thing we will do is to rename our channels so we can convert the CHOP’s to SOP’s without any extra steps. We will connect a rename chop after the math3 and we will type t[xy] and this will rename our channels first one as tx, and second as ty.

Then we need to add the tx channel, so we need to copy-paste pattern1 operator and make the following changes:

  • Channel Name: Change to ‘tz’
  • Type: change to Constant
  • Amplitude: Make it zero.
  • To range: Right click and select the ‘Delete Expression’ option.

Finally we merge again our channels to have them packed in one operator, the connect a null and convert this null to SOP’s using the CHOP to op.

And we see that our astrid is graphed.

TOP’s

We will place a Ramp TOP, then we export the samples parameter in constant1 to the resolutionX parameter in ramp1, and change resolutionY to 1.

Finally we change our pixel format to 32-bit float RGB.

Our R G B data will act as tx ty tz respectively.

STEP 2

The next step is to connect a math TOP to ramp1. After doing this we will select the Range section and will change the second box of to range parameter to python expression math.pi*2.

We will do this on R and G channels. (tx and ty respectively). This operation is because we are still working with radians.

STEP 3

We will connect a function TOP after math1 and we will make the next changes:

  • Function R(tx) = change to cos(x)
  • Function G(ty) = change to sin(x)
  • Function B(tz) = constant value
  • Constant Value = it need to be zero as we no have any amplitude in z axis.
  • Angle Units = change to Radians.

We can notice that we made the same operations we did before with CHOP’s but using only one operator.

STEP 4

Remembering that our cosine and sine functions are cubed we will connect a composite operator after function1 and we need to connect function1 three times into comp1. Our default operation is multiply, so we are multiplying our functions three times, and again we did this using just one operator for both functions.

Last we need to multiply our functions by a, so we connect a math TOP after comp1 and drag the parameter a defined in constant1 CHOP to the multiply parameter.

STEP 5

Lastly to visualize, we will connect a null to math2. Then we convert null1 to CHOP’s using TopTo CHOP and rename the channels:

  • Red = tx
  • Green = ty
  • Blue = tz
  • Alpha = delete as we won’t use it

Finally convert the topto1 CHOP to SOP. And again we have our astroid.

Python

STEP 1

We will use our default script DAT in the free file. And we will declare our parameter Samples and A with the next code:

def onSetupParameters(scriptOp):
	page = scriptOp.appendCustomPage('Parameters')
	p = page.appendInt('Samples', label='Samples')
	p = page.appendFloat('A', label='A')
	return

Then we save our script, click the Setup Parameters button and change the samples value to 100 and the A value to 1

STEP 2

Then we need to declare our parameters inside the script to make it readable:

def onCook(scriptOp):
	scriptOp.clear()
	
	#Declare Variables
	samples = scriptOp.par.Samples
	a = scriptOp.par.A
	cycle = math.pi*2

The assignment to the number of samples and the output channels come by default so when we save the script, we will see that the error is gone, the length of the scrip is the same as our defined samples and the output channels (tx,ty,tz) are visualized.

STEP 3

We will calculate the step size with the next operation

	#Calculate Step Size
	step = cycle/(samples-1)

and save the script.

STEP 4

Finally we need to make our equation and assign the values to the rigth channel. We will do it with the next code:

#Assign Value to channels Implementing the Parametric Equation
for i in range(samples):
	angle = step*i
	tx[i] = a*math.pow(math.cos(angle),3)
	ty[i] = a*math.pow(math.sin(angle),3)

Here we make a for loop that will be by the length of samples we defined and asigned to the script. Then we calculate the angle in every sample and we access to that sample in the corresponding output channel (tx and ty). And we will assign the value of our parametric equation:

a cos3 t = a*math.pow(math.cos(t),3)

a sin3 t = a*math.pow(math.sin(t),3)

As you can see here we use the power function of the python math library in which we first define the value that we want to power and then declare the power at which the value will be. So because our functions are cubed we need to type in 3.

Finally we connect a null to the script1 and convert using the ChopTo SOP and again we see the astroid in the screen.

And las but not least we will see some applications to the data that we have.

First we place a circle SOP, connect a Transform SOP and set up a render network. We will connect a RGB Key TOP after render1 to have our black background and we end with a null TOP.

In the transform SOP we will type 1/100 in the Uniform scale parameter. Then we place a Constand and Line Materials, and finally we turn on the in Instancing parameter on geo1 COMP.

We need to place a Select CHOP and drag any of the null chops we have with the astroid information. We go to geo1 Instance page, and drag the select CHOP we’ve created to Translate OP parameter, and select the corresponding channels.

We will create two Noise TOP’s, in which we will export the samples parameter we defined to the ResolutionX parameter, and we change ResolutionY to 1, and finally change the Pixel format to 32-Bit Float RGB. After this we rename one noise to color, and the other to scale.

In the color noise we will turn of Monochrome, and we will drag it to the Color OP in the Instance 2 page on geo1, and we will select the corresponding channels. Then we will drag scale noise to Scale OP in the Instance page on geo1, and we will select r in sx,sy,sc.

Finally we can play with the parameters on color and scale noise TOP’s, change between materials and changing the samples and a parameters on constant1.

I hope you enjoyed this tutorial see you soon!

RESOURCES

https://www.programiz.com/python-programming/methods/built-in/pow

https://mathworld.wolfram.com/Astroid.html

https://en.wikipedia.org/wiki/Astroid

PROJECT FILES

Design a site like this with WordPress.com
Get started