CinnamonMetal Posted November 1, 2017 Share Posted November 1, 2017 How do I compare two floats against a float value of 1.0 using Vector3.dot() ? if hou.Vector3.dot(primColor,rounded,1.0): print("match") else: print("no match") Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 1, 2017 Share Posted November 1, 2017 #Like this vector_one = hou.Vector3((1,0,0)) vector_two = hou.Vector3((1,0,0)) if vector_one.dot(vector_two) == 1: print 'match' #Or like this if hou.Vector3((1,0,0)).dot(hou.Vector3((1,0,0))) == 1: print 'match' -b 1 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 1, 2017 Author Share Posted November 1, 2017 if not hou.Vector3(primColor).dot and hou.Vector3(rounded).dot == 1: print("match") else: print("no match") The result is always no match; when it should be match ? Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 1, 2017 Share Posted November 1, 2017 You need to look at the code i posted one more time:) Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 2, 2017 Author Share Posted November 2, 2017 Correct me if I'm wrong, hou.Vector3 takes a tuple; I attempted using it without a tuple and it worked ? I'm referencing your alternative code example. I don't want to use integer or float values for the vector I want to use a variable containing a tuple; unless you were already aware of that based on my original question I'm looping over each primitive; with that in mind, my goal is to take a vector3 tuple compare that with 1.0 whether the truncated value is equal to that of the full float value based on color, if based on color is anything of importance to begin with ? Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 2, 2017 Share Posted November 2, 2017 (edited) Im not entirely sure what you actually want to do but if you want to use the dot product method of the hou.Vector3 class, you are not doing it the right way. In your code you are calling: hou.Vector3(primColor).dot This makes python return the method it self, not the value the function is supposed to return. If you print this you will get something that starts with "bound method..." To make this work you also need to supply the dot method with a vector: hou.Vector3(primColor).dot(rounded) The first statement will always return True whereas the second will return any vaule between -1 and 1. Depending on the directions of the two vectors (primColor and rounded) you pass in. Cheers Bonsak Edited November 2, 2017 by bonsak Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 2, 2017 Author Share Posted November 2, 2017 I have three sets of floats or a tuple. I'm going to take into consideration you're right; by right I mean I'm comparing a truncated tuple (Vector3) with the full value tuple (Vector3) otherwise made up of three float values (float,float,float) you get the idea Anyhow if they match, then the result should print "match" that isn't the case looping over primitives; rather I'm getting "no match" therefore, my problem may not be the Vector3 it may be the truncated tuple Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 2, 2017 Share Posted November 2, 2017 I think the problem is that you are not using the dot method the correct way. You are using "hou.Vector3(primColor).dot" but you need to use "hou.Vector3(primColor).dot(rounded)" hou.Vector3(primColor).dot will never return the dot product. It will return the method it self as i wrote earlier. -b Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 4, 2017 Author Share Posted November 4, 2017 hou.Vector3(primColor).dot(hou.Vector3((rounded))) == 1 I'm using it correctly but comparing 1 / 1.0. If my math is correct, then the full float values is multiplied by 1.0 and so is the truncated float value multiplied by 1.0; which would produce the same value which went in. Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 4, 2017 Share Posted November 4, 2017 (edited) What are the actual values of the "primColor" and "rounded" variables? -b Edited November 4, 2017 by bonsak Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 5, 2017 Author Share Posted November 5, 2017 15 hours ago, bonsak said: What are the actual values of the "primColor" and "rounded" variables? -b There different based on each primitive. Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 5, 2017 Share Posted November 5, 2017 As a rule of thumb you never compare two different float values using ==. Floating point arithmetic is not numerically precise, every operation performed on a float results in a "Floating-Point Error" (tiny imprecisions due to the nature of decimal representations on modern hardware). If you want to know if your color and your rounded values are normalized and parallel(which seems to be the question your asking?) then the most straightforward way would be, dot = hou.Vector3(primColor).dot(hou.Vector3(rounded)) tolerance = .000001 if dot >= 1.0-tolerance and dot <= 1.0+tolerance : print "match" . Houdini's Vectors types also have almostEquals functions which do similar tests for each element in the array. 1 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 5, 2017 Author Share Posted November 5, 2017 The condition using 'and' verifies whether the floating point value is down to an extremely small value to compare. Although I'm getting an error regarding the tolerance variable ? tolerance = 0.000001 Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 9, 2017 Share Posted November 9, 2017 I'm not sure what exactly your asking. tolerance = 0.000001 This works in my interpreter, I get 1e-06. What if dot >= 1.0-tolerance and dot <= 1.0+tolerance : does is check if dot is within 2*tolerance of 1.0. It's the same as saying abs(dot-1.0) <= 2*tolerance. So if tolerance was .001 on a number line it would look like,(not to scale) .9990 .9999 1.0 1.0010 1.0011 --------|-------x--------|--------|---------x1---- so x, being .9999, would be true as its greater then .9990 and less then 1.0010, but x1 would be false as its 1.0011 which is greater then 1.0010. Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 12, 2017 Author Share Posted November 12, 2017 I understand. What I don't understand is why the error ? tolerance = 0.000001 Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 12, 2017 Share Posted November 12, 2017 What are the actual values of primColor and rounded when you get the floating point error? Or are you getting an error just by declaring tolerance = 0.000001 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 13, 2017 Author Share Posted November 13, 2017 The primColor and rounding happen per primitive and works successfully except when I declare the tolerance variable along with a condition then it breaks. From what @MrScienceOfficer supplied as code should tell me per primitive whether the full float and truncated float values match. Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 13, 2017 Share Posted November 13, 2017 That code works for me, you need to post the error message. Quote Link to comment Share on other sites More sharing options...
bonsak Posted November 13, 2017 Share Posted November 13, 2017 Works for me as well. Why dont you post a file showing the error. -b Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted November 15, 2017 Author Share Posted November 15, 2017 (edited) I'm getting an error within the function. Does there appear anything wrong here ? tolerance = 0.000001 if dot >= 1.0-tolerance and dot <=1.0+tolerance: print("match") else: print("no match") Otherwise the error is; AttributeError: 'module' object has no attribute 'theLooper'; being the name of the function ? Edited November 15, 2017 by CinnamonMetal 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.