# Align card with vector

## Recommended Posts

Hi

Any chance you guys know how could rotate the card to match 2 vectors I have specified? (@N and @up)

Cheers

Janis

alignToVector.hip

##### Share on other sites

Hi,

one way might be using the sample covariance matrix of the geometry points and calculate the eigenvectors. These vectors can be used to align the geometry along x,y,z.

alignToVector.hipnc

##### Share on other sites

55 minutes ago, Aizatulin said:

Hi,

one way might be using the sample covariance matrix of the geometry points and calculate the eigenvectors. These vectors can be used to align the geometry along x,y,z.

Really appreciate it.

For now looking at it, if looks way over my head in vex and python.

So I don`t really know how to transform it back to original orientation. Also it doesn`t work when scaled down. and when I rotate the original card if flips from one side to another.

Just t clarify what I`m after. Im gonna have multiple cards around geo that I want to rotate and scale if for each loop. So my idea was to bring each card to origin align with XY axis then just use transform for scale and rotation, and then apply transforms back to card to get it back to original position and rotation(with new roation ac scale on top of those transforms).

Similar to this effect. just want to have control on scale and rotations based on normals from geo.

Cheers

Janis

##### Share on other sites

For now I use this setup. (for each is because I`m applying it to many cards)

But rotation doesn work if original card is facing different directions unfortunately

alignToVector2.hipnc

##### Share on other sites

Hi,

here is another version. In the first version I've used @P -= Center again, which was wrong. It has to be += and if you want the geometry to copy to another geometry this center should be the root.

It is better, that this root is zero vector.

There is another problem. The geometry is flipping, if you change the orientation. I will take a look at it later.

alignToVector2.hipnc

##### Share on other sites

Heres an example of how you can set it up.

mystique_01.hip

Edited by ThomasPara
Changed the file
##### Share on other sites

And here's another example, utilizing existing sop nodes instead of custom VEX

Disable the Channel SOP for tweaking, as recalculating the delay effect takes its computational toll...

##### Share on other sites

10 hours ago, Aizatulin said:

Hi,

here is another version. In the first version I've used @P -= Center again, which was wrong. It has to be += and if you want the geometry to copy to another geometry this center should be the root.

It is better, that this root is zero vector.

There is another problem. The geometry is flipping, if you change the orientation. I will take a look at it later.

Thanks. this works nicely(apart from flipping)

Just not sure how to do rotation and scaling and  then transform card to original position.

Thanks for the help!

##### Share on other sites

And here's another example, utilizing existing sop nodes instead of custom VEX

Disable the Channel SOP for tweaking, as recalculating the delay effect takes its computational toll...

These new nodes in H18 are gold! Orientation along curve!. shame can`t use 18 for this project. So doing this vex .

Cheers

##### Share on other sites

6 hours ago, ThomasPara said:

Heres an example of how you can set it up.

Thanks a lot. will look into this.

##### Share on other sites

Here is fixed version, where all orientation nodes are wrapped together into one node.

The only input is a base(root) point parameter, which has to be defined.

The flippings problem seems to be solved now.

It looks like, that copy to points works with it.

cov_eigenB.hipnc

##### Share on other sites

59 minutes ago, Aizatulin said:

Here is fixed version, where all orientation nodes are wrapped together into one node.

The only input is a base(root) point parameter, which has to be defined.

The flippings problem seems to be solved now.

It looks like, that copy to points works with it.

Dude you`re a legend!

Thanks a lot for this.

It`s gonna take some time for me to go through all the wrangles and understand how exactly it`s working

But it works good. apart from cards flipping.

I`ll upload part of my setup so it`s more clear what I`m doing.

I kinda made it work with building a polyframe and rotating,

This tutorial helped me a lot with trying to understand matrices and so on:

but it rotation work only on one axis and when I try scaling it acts bit funky (RotX and scaleY works nice).

That is why I thought bringing it to center. do all the rotations and transforms there and then transform it back to world space(for each card) would be a better solution.

Cheers

Janis

cov_eigenC.hipnc

##### Share on other sites

Same setup with your feathers, and with uniform scale.

Mystique_02.hipnc

##### Share on other sites

The flipping problem was due numerical inaccuracy. The problem is to get 4 points which are not in a plane. If the points are too close together following calculations may fail.

Once you are sure you have 4 points (with pt id), which are not in plane you can use them to avoid the flipping problem.

But anyway - I think for your problem this is not the best solution, because it is very time consuming. I like Thomas solution, because he is using the information of the surface to get the orientation and using point wrangle, which is quite fast.

If you have no other Information about Orientation this may be the only option or perhaps there are better solutions.

Just for completeness here is another file. I've changed a bit:

• there is an input for eps (accuracy) too small or too big values will not work
• the node outputs the transformation matrices for backtransformations
• I've added an example bend node with custom parameters based on foreach values and distance functions

Generally foreach offers more flexibility than parallel point wrangle or hard coded nodes, but in many cases it has less performance.

P.S. just as a quick and dirty method: to incease the performance you can also loop once over the geometry and save all necessary attributes into detail arrays referencing to each class.

Using these attributes you can transform each point (which shoud have a unique class) to X,Y,Z, perform your operations and transform it back.

Here is another modified example ("cov_eigenE")(which will probably not work for every situation just more to visualize what I mean).

Edited by Aizatulin
##### Share on other sites

In general i avoid "for-each" networks, it usualy becomes to slow. And when things get slow, art directing and creativity get worse. You can make hda's of your vex setups and then it gets as easy to use as a node. You can get a long way with learning how to use vectors, matrixes and quaternions.

• 2
• 1
##### Share on other sites

Yes I agree, but using quaternions will have true benefit in performance if you chaining (many) rotations.

##### Share on other sites

Thanks for all the help guys. Lots of files and setups to learn from.

I ended up just getting rot axis Vector(using N and up vector) and getting orient attribute with quaternion function. As this seems like the easiest way to rotate.

I bring each card to the center so I use transform just to scale them up uniformly.

Cheers

Janis

##### Share on other sites

• 1 year later...
For some of my personal work, i will like to be able to rotate, some piece along their most suitable candidate edge, and for this using some curve generate by shortest path like here or maybe gradient field.

i guess i will have to simplify the edge also off course to get some kind of median axis.
tIm not familiar with eigen, covariant matrice , probably i guess i have to use dot product once i make an approximation of the main edge of every piece and compare the normal or each to the tangent of the closest path or so...

Any TD around which might feel more comfortable here with the maths and don't mind to give a try this puzzle challenge?

Hip attached

Edited by vinyvince
##### Share on other sites

"White Dog" on Twitter have file Curve skeleton  , some tricks inside Maybe gonna Help if you not already found That @vinyvince

##### Share on other sites

It is now possible to do mystic effect with Hair comb tool

Edited by vinyvince

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

×
×

• #### Support

×
• Create New...