lets say you have two spheres in model.
Here is three situations to explain my problem.
1/->
sphere 1 is at 0,0,0
sphere 2 is at 2,0,0
vangle is 90
2/->
sphere 1 is at 0,0,0
sphere 2 is at 2,2,0
vangle is 90
3/->
sphere 1 is at 0.1,0,0
sphere 2 is at 2,2,0
vangle is 45
It doesnt make sense that sphere1 can't be at 0,0,0 to get accurate results. Its like you have to move it away from 0,0,0 to get expected values.
Anyone know more about the depths of vangle to explain this? I am using vangle the wrong way?
in the textport, used this expression to get the results:
echo `vangle( vector3 ( point(“/obj/model/sphere1”,0,P,0), point(“/obj/model/sphere1”,0,P,1), point(“/obj/model/sphere1”,0,P,2) ), vector3 ( point(“/obj/model/sphere2”,0,P,0), point(“/obj/model/sphere2”,0,P,1), point(“/obj/model/sphere2”,0,P,2) ))`
better format:
vangle(
vector3
(
point(“/obj/model/sphere1”,0,P,0),
point(“/obj/model/sphere1”,0,P,1),
point(“/obj/model/sphere1”,0,P,2)
),
vector3
(
point(“/obj/model/sphere2”,0,P,0),
point(“/obj/model/sphere2”,0,P,1),
point(“/obj/model/sphere2”,0,P,2)
)
)
expressions: vangle
5368 8 0-
- pyramation
- Member
- 176 posts
- Joined: July 2005
- Offline
-
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
You're probably using your vangle() correctly. I think the result is expected. The vangle() is same as doing acos(dot(normalize(v1), normalize(v2))). So when you take the dot product of {0,0,0} and {2,0,0} normalized, the result is 0. However, when you take the acos() of it to get an angle, the resulting angle would be 90 degree – acos(0) == 90.. Trouble is that, when you have a vector that's pointing at certain direction, and it's trying to project to another vector that's, well, a zero-vector, it doesn't make a whole lot of sense.
hope this help clear up a little…
hope this help clear up a little…
-
- edward
- Member
- 8141 posts
- Joined: July 2005
- Offline
-
- pyramation
- Member
- 176 posts
- Joined: July 2005
- Offline
well I just want to create my own lookat using expressions….
I was thinking a combination of vtorigin and vangle could maybe do the trick…
Pretty much I am trying to learn as much as possible about some of the “old school” ways to do things so I know houdini inside out. I've been trying to focus on expressions and scripting as much as possible.
I guess maybe Im jumping the gun here….but I am willing to learn :wink:
So are you saying normally you wouldn't use vangle on two points in the same hierarchy? …meaning like how vtorigin tranforms from obj to sop level?
If you wouldnt use two point positions….what would the use of vangle be….?
I was thinking a combination of vtorigin and vangle could maybe do the trick…
Pretty much I am trying to learn as much as possible about some of the “old school” ways to do things so I know houdini inside out. I've been trying to focus on expressions and scripting as much as possible.
I guess maybe Im jumping the gun here….but I am willing to learn :wink:
So are you saying normally you wouldn't use vangle on two points in the same hierarchy? …meaning like how vtorigin tranforms from obj to sop level?
If you wouldnt use two point positions….what would the use of vangle be….?
-
- EigenAlex
- Member
- 639 posts
- Joined: July 2005
- Offline
I can still use vangle() just like your case, but it'd all be depending on the context of what I am trying to achieve. Even the point position itself can be treated as vector. Well, it is a position vector after all… I use vtorigin(), originoffset(), etc. every now and then, but typically they happen at object level. I don't think I remember ever using them in SOPs…
There is a matrix function mlookat() that would allow you to do a lookat function. perhaps this is what you're after? Do a exhelp on mlookat. The example in there should be exactly what you need to get your lookat to work.
There is a matrix function mlookat() that would allow you to do a lookat function. perhaps this is what you're after? Do a exhelp on mlookat. The example in there should be exactly what you need to get your lookat to work.
-
- pyramation
- Member
- 176 posts
- Joined: July 2005
- Offline
nice….mlookat() definetly looks cool.
from the help:
explodematrix(mlookat(vector("“),vector(”“)), ”RST“, ”XYZ“, ”RZ")
My translation of the above code:
(please let me know if this is correct)
“if you transform vector one using the order rotate, scale, then translate; using the order x, y, then z, to where vector two's values are… echo what the rotate z value would be for the transformation to occur”
just trying to make sure I'm understanding this one correctly.
from the help:
explodematrix(mlookat(vector("“),vector(”“)), ”RST“, ”XYZ“, ”RZ")
My translation of the above code:
(please let me know if this is correct)
“if you transform vector one using the order rotate, scale, then translate; using the order x, y, then z, to where vector two's values are… echo what the rotate z value would be for the transformation to occur”
just trying to make sure I'm understanding this one correctly.
-
- edward
- Member
- 8141 posts
- Joined: July 2005
- Offline
TheUsualAlex
Even the point position itself can be treated as vector.
To clarify on that for lynch_ppl, positions are just locations in space. I had previously meant “vector” in the mathematical sense, ie. as a direction. They can both be represented as 3 numbers associated with them (in 3D), but they mean two different things. The vector3()'s given to vangle() are interpreted as directions. If you give it two different positions, then they will be treated as two vectors emanating from the origin. There isn't a reasonable answer for calculating an angle between something with a zero vector (see last paragraph for perhaps a better explanation).
lynch_ppl
well I just want to create my own lookat using expressions….
Lookat in what sense? I only notice that you have two point positions. Doing a lookat implies you're trying to align two directions which means you need at least three points. From what to what are you trying to form a lookat for?
Since it looks like you're only dealing within the same SOP world, I don't think you need to take into hierarchy. If you were dealing with SOPs in different objects, then you would need to take it into account. I still don't have a clear idea on what exactly you're trying to achieve though. BTW, vtorigin() only works with objects, you can't give it a SOP path and get meaningful results.
Let's consider a more graphical example of vangle(). Say you have two line segments emanating from the same point and you want to calculate the angle between them. Let's call the common point O and the other points, A and B. Then if they were vector3()'s, vangle(A-O, B-O) will give you the angle in between your two line segments. If either of point A or B has the same position as O, then at least one of the line segments is zero length. So in that case, you can't get a sensible answer because you really only have 1 direction. If both A and B had the same position as O, then you have no directions to compute the angle at all. I kinda like your post because it ties into my recent forum signature quite well.
-
- pyramation
- Member
- 176 posts
- Joined: July 2005
- Offline
Thank you Edward for the in-depth elaboration on vectors, direction and vangle…I'm definetly in a better place with understanding it.
As far as a lookat…I just basically wanted to recreate what one can do with the point sop using the $TX-TX2 $TY-$TY2 $TZ-$TZ2 in the normals and it would point the object in the direction of the second referenced position.
And I just want to clarify…when is a good place for using vector3 vs vector?
How do you know how an expression will interpret a vector? Does use change depending on the situation?
Last thing….in my last post…was I correct on my interpretation of that explodematrx() expression?
As far as a lookat…I just basically wanted to recreate what one can do with the point sop using the $TX-TX2 $TY-$TY2 $TZ-$TZ2 in the normals and it would point the object in the direction of the second referenced position.
And I just want to clarify…when is a good place for using vector3 vs vector?
How do you know how an expression will interpret a vector? Does use change depending on the situation?
Last thing….in my last post…was I correct on my interpretation of that explodematrx() expression?
-
- edward
- Member
- 8141 posts
- Joined: July 2005
- Offline
In the Point SOP, you can just put your subtraction expressions in the Normals parameter of the Point SOP then. There's only 1 direction here so you don't need vangle at all. If you don't want to use a Point SOP, you can also use the AttribCreate SOP with N and “vector” as your type.
The difference between vector3() and vector() is that vector() allows you to create variables which have components different than 3 (ie. 2, or 5, 6, etc.). vector3() and vector4() are both (much) faster than vector() when creating variables which have 3 or 4 components respectively.
As for which functions interpret their parameters as position or direction, it will depend on the expression function. mlookat() for example, requires directions.
For the explodematrix(), I think you have it right. mlookat() produces a matrix transform from one vector to another. explodematrix() extracts the translates/rotates/scales representation of that transform. You can google for lots of information on matrix. Mike Cronin started a matrix tutorial on odforce here [odforce.net].
The difference between vector3() and vector() is that vector() allows you to create variables which have components different than 3 (ie. 2, or 5, 6, etc.). vector3() and vector4() are both (much) faster than vector() when creating variables which have 3 or 4 components respectively.
As for which functions interpret their parameters as position or direction, it will depend on the expression function. mlookat() for example, requires directions.
For the explodematrix(), I think you have it right. mlookat() produces a matrix transform from one vector to another. explodematrix() extracts the translates/rotates/scales representation of that transform. You can google for lots of information on matrix. Mike Cronin started a matrix tutorial on odforce here [odforce.net].
-
- Quick Links


