# Python SOP: Bend curve by vector.

## Recommended Posts

Hello.

I have the little task. i need to bend curve by vector.

It must be like tree branch on the wind.

task is simple - we need to rotate every point around previous point since angle between current point position equals bend vector's direction.

1. Get point's pivot (its previous point's position)

2. Get cross-product between point position and bend vector direction

3. Rotate point since angle between point's position and bend vector becomes equals 0

I spend a few weeks with matrices, hou module and other ways to do this and decided to write here about this. I attach images of this effect

Could you suggest correct algoritm of this task and necessary technics?

Thanks

Edited by evgen
##### Share on other sites

Hello.

I have the little task. i need to bend curve by vector.

It must be like tree branch on the wind.

task is simple - we need to rotate every point around previous point since angle between current point position equals bend vector's direction.

1. Get point's pivot (its previous point's position)

2. Get cross-product between point position and bend vector direction

3. Rotate point since angle between point's position and bend vector becomes equals 0

I spend a few weeks with matrices, hou module and other ways to do this and decided to write here about this. I attach images of this effect

Could you suggest correct algoritm of this task and necessary technics?

Seems to me, you would need to transform all points to make the first bend, then transform all points to make the second bend etc.

If you're trying to do it all with one transformation, the algorithm as it stands would not work.

You also need to make sure your point order is correct, and, when trying to do it with VOPs, you can't even be sure that the points are processed in order (they are not).

I think you either need to do it with a ForEach SOP, which might be slow, or in VOPs and essentially calculate the the result for all points (at least up to current point) for each current point. This means you're doing a lot of redundant calculations, but might be faster in the end even so

Might be I'm overlooking something obvious, though

##### Share on other sites

Could you suggest correct algoritm of this task and necessary technics?

Ohh, I just had to try it - this is with a TransformAxis SOP inside a ForEach SOP.

The vector manipulation can get a bit out of hand when using expressions, so doing this in a VOPSOP inside the ForEach would be nicer.

ee_bend_v002.hip

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×