Jump to content

Dot Vector in Python ?


CinnamonMetal

Recommended Posts

#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

  • Thanks 1
Link to comment
Share on other sites

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 ? ;)

Link to comment
Share on other sites

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 by bonsak
Link to comment
Share on other sites

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 :unsure:

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Confused 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by CinnamonMetal
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...