Jump to content

Comparing vectors in Vops


SteveNi

Recommended Posts

Hi.

I have two vectors and I want to check if they are equal or not, so this is what I did so far:

http://prntscr.com/cfxu8d

The vectors Im trying to compare are the normal of the grid (created by me in a create attribute SOP) and the vector wich starts from the grid and points to a sphere.

If the vectors are equal I set the color of the grid green, otherwise red.

In the vop sop I normalized the 2 vectors because I saw online that two vectors to be equal must have the same magnitude too, but even after normalizing them it still doesnt work.

Why?

 

 

 

Vectors_check.hipnc

Link to comment
Share on other sites

Testing two floating point numbers or vectors for absolute equality is very unsafe.

What you should do is is test whether their difference is below a given (very small) epsilon value.

if ( ( float x - float y ) < 0.0001 )

or

if ( length( vec x - vec y ) < 0.0001 )

 

Link to comment
Share on other sites

6 minutes ago, sasho78 said:

To answer your question in VOP context, it seems that "Compare" OP works only with float values, so you may have to use "vectorToFloat" OP and compare vector values separately and then use "And" OP to control "TwoWay" OP.

 

Subtract the two vectors from each other, Subtract VOP, calculate the length of the difference vector, Length VOP, compare the length to 0.0001, Compare VOP, feed to Two Way Switch VOP.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...