10 October 2011  
Veteran
portfolio
Sureshkumar
India

Object's direction
Hello folks,
How to find a object's direction in MEL? whether in it is in X direction or Z direction from current position? If any formula should be used or what? 
10 October 2011  
HighEnd3D deserter
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester,
United Kingdom

If you are refering to an objects direction as being the vector of it's local or world X, Y or Z axis, you could just extract the X, Y or Z axis from the objects local or world matrix. Assuming the matrix is got as 16 floats (i.e. via xform or getAttr) components [0:2] are the X axis vector, [4:6] are the Y axis vector and [8:10] are the Z axis vector.
:nathaN 
10 October 2011  
Veteran
portfolio
Sureshkumar
India

Originally Posted by NaughtyNathan:
If you are refering to an objects direction as being the vector of it's local or world X, Y or Z axis, you could just extract the X, Y or Z axis from the objects local or world matrix. Assuming the matrix is got as 16 floats (i.e. via xform or getAttr) components [0:2] are the X axis vector, [4:6] are the Y axis vector and [8:10] are the Z axis vector.
:nathaN Hi nathan, I need to find the world position only. Fox example, Locator(A), plane(B) are the two objects I got. A is at Orgin. B will be in any(+x,x,+zz) direction from A. Based on the distance between two objects and the direction Im adding some lights on the plane. To calulate distance my first component is Y and the second one is X or Z. So if I know the locator's position from the plane I can decide X or Y to pass it. hope you got my problem. 
10 October 2011  
HighEnd3D deserter
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester,
United Kingdom

sorry dude, no. I have no idea what your are talking about here. :(
Maybe you need to describe your problem a little more clearly, or provide a diagram..? I have no idea whether you want direction or position:
Quote:
How to find a object's direction in MEL?
... I need to find the world position only. :nathaN 
10 October 2011  
Veteran
portfolio
Sureshkumar
India

Originally Posted by NaughtyNathan:
I have no idea whether you want direction or position:
Nathan, I just need the direction, sorry for the confused edition . In the picture A is located in Z direction from B. Now I know the direction so I can calculate the distance by using Y and Z values of both object's position. what if the A located in Z or X or X from B, Is there any way to find the direction easily rather than many calculations? Once I find the direction then I can find the distance between two objects. heres the link of my example screen shot. 
10 October 2011  
Expert
...
United Kingdom

Originally Posted by cppgraphics:
Once I find the direction then I can find the distance between two objects.
The distance tool under 'Create > Measure Tools > Distance Tool' can give you the distance between two objects. There's also the distanceBetween node that uses two objects positions to determine distance. You can find the world space positions of two objects, subtract one from the other to obtain the vector (doesn't matter which order you subtract) then use the mag command.

10 October 2011  
Lord of the posts
portfolio
Wesley Howe
Rockdale,
USA

You can also use the good old Pythagorean method. Square the differences between each component (X1  X2) * (X1  X2), sum all three dimensions, and extract the square root with sqrt().
<* Wes *> __________________
i7 2.8ghz w7pro 8gb quadro 4000 w/270.51 driver, 600 GB SSD C: Drive 
10 October 2011  
HighEnd3D deserter
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester,
United Kingdom

I'm not entirely sure he want's this simple kind of distance... I'm sure he's trying to do something related to facing direction, but I can't make head nor tail of his explanation...
Maybe if you simply explained what you were trying to achieve with this idea (e.g. a script that hides all objects that are not going to be hit by a given light source, or whatever) we could give you more specific help or pointers? :nathaN [edit]ah! maybe he does want the distance, but in terms of a LOCAL X and/or Y and/or Z offset? is that it cppgraphics?[/edit] Last edited by NaughtyNathan : 10 October 2011 at 10:05 AM. 
10 October 2011  
Veteran
portfolio
Sureshkumar
India

Thanks for your replies folks.
I used Pythagorean method, it seems like I used wrong formula. I have taken 2D distance formula and thought one point is Y and other point I should use either X or Z. From WesHowe's reply I got the right formula. @ Nathan, This is a script to create truss light setup, the colorful focus lights we will see in stage shows. Actually I need the distance between those two objects, to setup the length of the light's fog. Heres the rendered output of the script. http://vimeo.com/30890084 
10 October 2011  
Expert

Thread automatically closed
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. 
Thread Closed share thread 
«
Previous Thread

Next Thread
»


