Author Topic: How to detect directions for paths?  (Read 235 times)

If I have an arbitrary edge/path in an image that may be oriented and curved in any direction, is there any way to detect the "length" vector of that path? Or perhaps the perpendicular direction of it? If I convert the (blurred) path into a normal map, I get 2 perpendicular directions on either side of the path, so that is one possible tool.

My eventual goal is to find ways to shorten the path along its length or along its end points (by vector warping it or such).

Note 1: One thing I tried was to convert to normals (using the blur method above), then use a pixel processor to convert all vectors to "absolute", making them all point in the same perpendicular direction to the path. But this causes strange problems when the path traces out circular curves - the vectors flip completely around during some angled turns, because there is no way to detect which side is the "inside" of the path.

Note 2: There may also be something that could be done with the tile sampler. It is possible to generate perpendicular lines across all paths using the masking threshold and vector rotation options. These lines would represent path direction "checkpoints". But I'm not sure where to go from there. Maybe blur these lines, convert to normals, then process them some how? Still not much better than just having the path slope.

Note 3: If we take the blurred path converted to normals and rotate them by 90 degrees (using vector rotation node), we get vectors that trace around the path like a race track. If there was some way to force the vectors on both sides to point the same way, it would result in the path direction everywhere except on the ends. Maybe some way of masking out one side and blending that with a second version that is rotated the opposite way by 90 degrees? I'm just not sure how to mask these out accurately. Or maybe a pixel processor that samples vectors from both images and captures the ones facing toward each other? But then I can think of no way to generate a result vector that bends around curves correctly (same problem as note #1).

If anyone has any ideas to pull this off, please let me know.
Thanks!
Last Edit: March 04, 2019, 06:59:32 pm

I created a node that finally makes this possible. It is attached for anyone else who may need it. You plug a normal map into it and it will allow you to generate a mask based on an angle and dot product range. So to generate the vectors for a path, you just mask out left (angle=0.5) and use that as a blending opacity to merge two rotated versions of it (use vector rotate node, one at -90 degrees, the other at +90 degrees).

The angle test ignores depth for the most part. But I did add a depth range filter as well in case it may be useful to someone.

Obtaining the path vectors is still not perfect, because the angle chosen for the mask must be a specific angle. If I can find a way to mask angles based on some other criteria, it may get better. But if your paths are more predictable, this will work great.
Last Edit: March 05, 2019, 02:24:57 pm