Jump to content

NOOB - my first vex - collatz conjecture - I am stuck!!


majinpu

Recommended Posts

Hi there!

A few days ago I saw a video on youtube talking about the collatz conjecture and I decided to recreate it inside Houdini using VEX.

I have almost completed it. But I got stuck at one point.

here is the link https://www.youtube.com/watch?v=LqKpkdRRLZw&feature=youtu.be

 

The process is pretty simple. I have just followed what the video says.

Here's what I did. 

First thing, I just scatter some points, and create a random integer attribute called "numbers".

Then I set another attributes that is called type, that just takes my number and modulate by 2. so I can separate my even number from odd number.

Then i put a solver. go inside.

After this I say, if type equal 0 (even) add 1 to @P.x and to @P.Y. If equal to 1 (odd) subtract 1 from @P.x and add 1 to @P.y

At the end I lookup for the number if it's equal to 0 or 2 I remove the point.

 

So far so good. but if you have a look in the video link at 3:40 it shows the pattern changing from straight lines to curved lines. 

At 3:24 is talking about adding some sort of degrees based on the direction the point is going. but I don't know how to achieve that!!

 

Somebody has got any Idea on how to do that? I have attached my hip file.

THANK YOU A LOT!!

 

 

 

MY VEX2.hiplc

Link to comment
Share on other sites

Good find! After a pointgenerate node I put this in a pointwrangle. The while loop draws new curve segments until num reaches 1. And dir defines where the curves bend to.

int i = chi('steps');
float spread_l = chf('Left');
float spread_r = chf('Right');

i@num = @ptnum;
vector pos = @P;
vector dir = {0, 1, 0};
int prim = addprim(0, "polyline");

while(@num > 1 && i > 0){
    i -= 1; // break

    if(@num % 2 == 0){
        @num /= 2;
        dir.x += spread_r;
    }
    else{
        @num = (@num * 3) + 1;
        dir.x -= spread_l;
    }  
    
    dir = normalize(dir);
    pos += dir;
    int pt = addpoint(0, pos);
    addvertex(0, prim, pt);
}

collatz_conjecture.hipnc

collatz.png

collatz2.png

Edited by konstantin magnus
added some color variation and jitter to the hip
  • Like 1
Link to comment
Share on other sites

put a visualizer on your wrangle and look at what is happening that way you can see exactly what dir is doing when isnt normalize, and I believe it will make sense to you, look at the geo spreadsheet.

you can see all the wacky numbers, etc. Most of the time you will want your vector to be normalized to make math operations.

lalanms.gif

  • Like 1
Link to comment
Share on other sites

I got it !! thanks Sepu! before I removed the dir = normalize(dir) and I understood that we are simply normalizing the dir every iteration and starting with a new P every time. so the points are not moving exponentially!!!

 

thanks a lot guys!! I learned a lot today

 

 

Link to comment
Share on other sites

dir is declared as a vector right, so you need to change it to 

Type : Marker

Style : vector 

Add what kind of Attribute you want to visualize, P, N, etc or it can be your own attribute as well, which in this case is dir.

As you can see the visualize node allows to look at thing in different ways. Depending of your needs you will change that.

 

Edited by Sepu
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...