### Need help for rolling a line into a spiral

533   10   0 Member 1 posts
Joined: March 2020
Offline
Hi, I'm new to Houdini and I am struggling with one task which I thought will be simple.

I have a line with 50 points (I tried with a line, curve and just copied points) which I am trying to bend into a spiral (I tried using bend, but it makes perfect circles, and I want a spiral, I also tried to use attribute wrangle to set rotation on points manually, but I was not able to set correct pivots for each point, they all have the same pivot).

What is the approach here in general if I want to roll something into a spiral.

The thing that I am trying to do is to roll rice mat into a sushi roll. Member 222 posts
Joined: Feb. 2017
Offline
Hey constantgenerator,

the bend sop is one way to do it. you have to adjust the capture direction to make it spiral.
take a look.

Cheers
CYTE

Attachments:
roll.hiplc (109.6 KB) Member 599 posts
Joined: Jan. 2018
Offline
SideFX Labs Spiral?

https://www.sidefx.com/products/sidefx-labs/sidefx-labs-tools/ [www.sidefx.com]

I made a tutorial on SideFX Labs excellent set of tools, including Spiral. You can watch it here:

>>Kays Member 418 posts
Joined: Feb. 2017
Offline
point SOP, dropdown preset Member 183 posts
Joined: June 2017
Offline
It is interesting to see different ways to do this. I would use an attribute expression node to make this spiral. If you allow editing of contents on the lab spiral solution, you can see how they did it. But here is a three node solution (with a couple extra nodes to create a sushi wrap.

Update, I realize this is probably what was meant by point sop.
Edited by Island - May 15, 2020 18:49:18

Attachments:
SpiralExpression.hiplc (98.0 KB) Member 2418 posts
Joined: Feb. 2012
Offline
```#include "math.h"
#include "voplib.h"

float easeOutCirc ( float t )
{
return sqrt ( 1 - ( pow ( ( 1 - t ), 2 ) ) );
}

float index = @ptnum;
float numpts = @numpt;
float startAngle = radians ( ch("angle") );
float dir = 2 * ch("dir") - 1;
float steps = ( numpts - 1 ) / ch("turns");
float stepAngle = ( 2 * PI / steps ) * dir;

float inc = index / ( numpts - 1 );
int mirror = chi("spherical");
float linear = ( 1 + mirror ) * inc;
if ( mirror && index + 1 > numpts / 2 )
linear = ( 1 + mirror ) * ( 1 - inc );

float circ = easeOutCirc ( linear );
float interp = linear + ( circ - linear ) * ch("roundness");
float r = ( ch("rx") + interp * ( ch("ry") - ch("rx") ) );

//  Apply power to radius at the end (after curvature)
inc = ( ( numpts - 1 ) - index ) / ( numpts - 1 );
float theta = 2 * PI * inc;
if ( mirror && index + 1 > numpts / 2 )
theta = 2 * PI * ( 1 - inc );
r *= pow ( ch("falloff"), theta );

float angle = index * stepAngle + startAngle;
float x = sin ( angle ) * r;
float z = cos ( angle ) * r;
float h = index / ( numpts - 1 );
float y = vop_bias ( h, 0.5 * ch("bias") + 0.5 );
y = vop_gain ( y, 0.5 * ch("gain") + 0.5 ) * ch("height");

matrix3 xform = dihedral ( { 0, 1, 0 }, { 0, 0, -1 } ) * lookat ( 0, normalize ( chv("n") ) );
@P = ch("scale") * set ( x, y, z ) * xform + chv("t");
```

Create a line and copy this code inside a point wrangle node. Make sure to set Scale, Height, Ry, Falloff to a positive value like 1, Turns to 5, N to {0, 1, 0} if your input line is along Y. It can also create spherical spirals, etc.
Senior FX TD @ Industrial Light & Magic Member 837 posts
Joined: May 2006
Offline
http://www.tokeru.com/cgwiki [www.tokeru.com] Member 508 posts
Joined: Sept. 2013
Offline
Or this:

```float u = vertexprimindex(0, i@ptnum) / float(primvertexcount(0, i@primnum));
matrix3 m = ident();
float amount = chf('amount') * u;
vector axis = {1,0,0};

rotate(m, amount, axis);

v@P *= m;
```

Attachments:
spiral.hipnc (74.8 KB) Member 183 posts
Joined: June 2017
Offline
There are probably more elegant ways of doing this (and more mathematically correct), but here is an unwrap of a spiral with reasonable UV's. Note: due to changing number of points on spiral curve, the transform UV scale had to be keyframed on the extruded spiral. There is probably a simpler way of doing this, but I don't know it. The length of a spiral curve also does not have an exact solution in calculus, so I made a few approximations.
https://vimeo.com/420120985 [vimeo.com]
Edited by Island - May 19, 2020 13:55:38

Attachments:
SpiralUnwrap.jpg (1.1 MB)
SpiralUV.hiplc (672.8 KB) Member 183 posts
Joined: June 2017
Offline
I actually think Konstantin's method is better than mine (and Animatrix's method is particularly good for more complicated spirals). In mine, the ramp actually compresses the material during the unroll, which is undesirable. I modified Konstantin's method slightly, but I'm not sure how to get the UV's to map properly, but the shape itself is great. If anyone knows how improve the UV mapping, I would be curious. The only thing I can think to keep the UV mapping correct is to actually unwrap the spiral, using the method described in cgwiki.
Edited by Island - May 21, 2020 10:41:27

Attachments:
KonstantinMethod.jpg (907.5 KB)
spiralM2020.hiplc (546.1 KB) Member 508 posts
Joined: Sept. 2013
Offline
I have improved the code and updated the hip file to illustrate it's working on multiple curves at once. As opposed to the usual @ptnum / float(i@numpt - 1).

```int seed = chi('seed');
float u = vertexprimindex(0, i@vtxnum) / float(primvertexcount(0, i@primnum) - 1.0);
float turns = fit01(rand(i@primnum + 12 * seed), 0.1, 1.0);

matrix3 m = ident();
float amount = chf('amount') * u * turns;
vector axis = {1,0,0};
rotate(m, amount, axis);

v@P *= m;
```
Edited by Konstantin Magnus - May 21, 2020 07:33:45

Attachments:
spirals.jpg (28.9 KB)
spiral.hipnc (84.5 KB)
{"ft_lang_label":"__label__en","ft_lang_prob":0.8687048,"math_prob":0.9507956,"size":6215,"snap":"2020-24-2020-29","text_gpt3_token_len":1833,"char_repetition_ratio":0.10143294,"word_repetition_ratio":0.29073757,"special_character_ratio":0.31954947,"punctuation_ratio":0.15952381,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9744876,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44],"im_url_duplicate_count":[null,null,null,6,null,null,null,6,null,null,null,null,null,null,null,5,null,null,null,8,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,8,null,null,null,8,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-13T21:17:29Z\",\"WARC-Record-ID\":\"<urn:uuid:0db31b56-1d67-449b-9c23-cb99e4340534>\",\"Content-Length\":\"84951\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1b2b2b7f-e719-49f9-94fa-a221af3d86a1>\",\"WARC-Concurrent-To\":\"<urn:uuid:2bd66567-c896-498e-b3a2-0540eac82153>\",\"WARC-IP-Address\":\"206.223.178.168\",\"WARC-Target-URI\":\"https://www.sidefx.com/forum/topic/73604/\",\"WARC-Payload-Digest\":\"sha1:NV7Z45TGQRN7QVRMELY3FHVUTK6RCGR7\",\"WARC-Block-Digest\":\"sha1:XH3B3ZATYUG6OSSAE6MPYDRMLZVVC627\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593657146845.98_warc_CC-MAIN-20200713194203-20200713224203-00555.warc.gz\"}"}