# [SOLVED]vector distance to surface for grooming hair

## Recommended Posts

Hi,

How could I measure vector distance to another surface like you see here.

Not just closest point distance, but distance following the vector.

I would like to use this as length point attribute in hairgen to control the shape of groom with geo.

Cheers

Janis

Edited by cudarsjanis

##### Share on other sites

As you can see it doesn`t work with just measuring the distance, if I change the vector direction

Vector_length2.hip

##### Share on other sites

use 'intersect'  function to find point on surface along vector

• 1

##### Share on other sites
3 hours ago, tamagochy said:

use 'intersect'  function to find point on surface along vector

Hi Andrii,

So I`m getting somewhere with intersect, but missing still something.. What am I doing wrong here?

As when I put addpoint it does creates the new points exactly where I need them, but when I measure distance attribute, something is still not matching.

Thanks

Janis

Vector_length3.hip

##### Share on other sites

Hi there,

I would use the intersect vex function, so create a wrangle and wire the tube in second input, and you can write something like:

```vector pos;
vector uvw;
int prim = intersect(1, @P, @N, pos, uvw);

f@length = distance(@P, pos);

@P = lerp(pos, @P, chf("mix"));```

So the original position is first input, and intersect vex function will take that position and emit ray to your target tube, and of cause the ray direction is the normal, and it will create the hit position and hit uv. So the hit position, which is "pos" in the code is the target intersected P that based on your normal direction. So compute the distance of @P and pos is the length you want.

Also you can mix the original P and intersect P to see the blending movement.

Hope this would help.

Edited by jimeng20
• 1

##### Share on other sites

Hi,

normalizing @N in wrangle1 and setting length to 1 in hairgen give me better results.

• 1

##### Share on other sites
13 hours ago, jimeng20 said:

Hi there,

I would use the intersect vex function, so create a wrangle and wire the tube in second input, and you can write something like:

```
vector pos;
vector uvw;
int prim = intersect(1, @P, @N, pos, uvw);

f@length = distance(@P, pos);

@P = lerp(pos, @P, chf("mix"));```

So the original position is first input, and intersect vex function will take that position and emit ray to your target tube, and of cause the ray direction is the normal, and it will create the hit position and hit uv. So the hit position, which is "pos" in the code is the target intersected P that based on your normal direction. So compute the distance of @P and pos is the length you want.

Also you can mix the original P and intersect P to see the blending movement.

Hope this would help.

Thanks Jie for explanation, it works!!

8 hours ago, Aizatulin said:

Hi,

normalizing @N in wrangle1 and setting length to 1 in hairgen give me better results.

Spot on Aizatulin! That is what I was missing. So everything was correct in vops, just needed to normalize the N beforehand!

Cheers

I`ll add the hip here, if anyone needs it, grooming specific shape is so much more controllable than using guideadvect.

Vector_length4.hip

• 2

## Create an account

Register a new account