SteveNi Posted September 9, 2016 Share Posted September 9, 2016 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 Quote Link to comment Share on other sites More sharing options...
eetu Posted September 9, 2016 Share Posted September 9, 2016 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 ) Quote Link to comment Share on other sites More sharing options...
haggi Posted September 9, 2016 Share Posted September 9, 2016 Another option could be to check the dot product. if( dot(v1, v2) > 0.9999) 1 Quote Link to comment Share on other sites More sharing options...
dimovfx Posted September 9, 2016 Share Posted September 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
SteveNi Posted September 9, 2016 Author Share Posted September 9, 2016 Yep, I forgot you shouldn't try to compare floating point values...my bad. I used the dot product method and seems to work, Thanks everyone! Quote Link to comment Share on other sites More sharing options...
eetu Posted September 9, 2016 Share Posted September 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.