# transforming a Vex-built PolyLine

## Recommended Posts

Hello to all!

I am currently writing a wrangle-thing in which I'm hoping to generate a random "hair" on every point and make it face the normal of said point.

The way I planned it is as follows:

1. create the hair w/ random params on 0,0,0

2. rotate the hair to Normal of the point that it's "generated on" w/ rotate(matrix,angle,vertex) function

3. Move the hair to @P

I'm not a hero with vector math, otherwise I'd generate the whole hair thing along a normal.

I wonder if I somehow can construct a identity matrix, like one would do with the ident() function, and use that to transform the prim.

Is there a way to simply rotate a primitive using something simpler than extreme vector math?

sgamhar.hip

##### Share on other sites

There is a preset to Grow Hairs on the point wrangle, might give you some tips:

##### Share on other sites

Just create a point at the same position and displace by normal @P += @N (or multiply) and connect them

##### Share on other sites
On 6/6/2018 at 5:52 PM, Yon said:

Just create a point at the same position and displace by normal @P += @N (or multiply) and connect them

Could you explain a little bit more?

I don't quite get it...

Does the displace by normal take care of origin-based rotation? I guess it'll have to be multiplication then.
I'll try it out, at least what I can make of your advice!

##### Share on other sites

Ah, I finally get what you've been trying to tell me. That part would've gone in the actual "hair grower" part of the algorithm, but the thing is that I can't use that because I have a twirl thing based
on some simple goniometric mathematics.

I'll be doing more experiments and trying things out.

I'll probably end up making every hair a new primitive, and using a primitve wrangle after that to wrangle them in the correct spot.

##### Share on other sites
Posted (edited)

Hello to all. I solved the math problem, ended up using the qrotate function together with quaternion in vectoraxis mode.

I botched it a bit using the normal as the axis, multiplying it slightly, and then correcting the angle based on wether the dot product of the Normal and the up vector was positive or negative.

I'm stoked this even works. I love houdini for its "multiple ways to rome" capabilities.

I still don't understand nothing about quaternions but this at least gives me a vague ideo on how to use them.

Thanks again for the help. I've included what I have now, to share with everybody.

--

I did it even more properly now, using the dihedral function. This is WAY less hassle than before.
I knew this function existed, but I never saw the use for it until now.
the basic structure goes like this:

```//define original vector (our line "grows" on the Y axis)
vector known_vector = set(0,1,0);

//compute what kind of rotation it would take to rotate points from the first vector (in our case {0,1,0} since the built line goes up), to the normal vector.
vector4 rot_quaternion = dihedral(known_vector,@N);

//rotate point position into place
position = qrotate(rot_quaternion,position);```

so easy. so perfect. Math is amazing.

I've implemented it and uploaded the file, so take a look if you want.

sgamhar_3.hip

Edited by sasbom
I have learned more and wanted to elaborate.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account