CGTalk Object's direction
 10-19-2011, 07:05 AM #1 cppgraphics Veteran portfolio Sureshkumar India   Join Date: Sep 2009 Posts: 39 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? share quote
 10-19-2011, 11:34 AM #2 NaughtyNathan HighEnd3D deserter   Naughty Nathan Technical Artist Sony SCEE Liverpool Manchester, United Kingdom   Join Date: May 2008 Posts: 2,608 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 share quote
10-20-2011, 05:03 AM   #3
cppgraphics
Veteran
portfolio
Sureshkumar
India

Join Date: Sep 2009
Posts: 39
Quote:
 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,+z-z) 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-20-2011, 09:56 AM   #4
NaughtyNathan
HighEnd3D deserter

Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester, United Kingdom

Join Date: May 2008
Posts: 2,608
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-21-2011, 05:28 AM   #5
cppgraphics
Veteran
portfolio
Sureshkumar
India

Join Date: Sep 2009
Posts: 39
Quote:
 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-21-2011, 09:43 PM   #6
mlefevre
Know-it-All

matt
technical artist
sony
United Kingdom

Join Date: Nov 2007
Posts: 411
Quote:
 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.

Code:
```string \$sel[] = `ls -sl`;
vector \$A = `xform -q -ws -translation \$sel[0]`;
vector \$B = `xform -q -ws -translation \$sel[1]`;
float \$dist = mag(\$A - \$B);```
__________________

 10-21-2011, 10:47 PM #7 WesHowe Lord of the posts   portfolio Wesley Howe Rockdale, USA   Join Date: Apr 2009 Posts: 667 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 share quote
 10-22-2011, 09:58 AM #8 NaughtyNathan HighEnd3D deserter   Naughty Nathan Technical Artist Sony SCEE Liverpool Manchester, United Kingdom   Join Date: May 2008 Posts: 2,608 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 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-22-2011 at 10:05 AM. share quote
 10-22-2011, 12:09 PM #9 cppgraphics Veteran portfolio Sureshkumar India   Join Date: Sep 2009 Posts: 39 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 share quote
 10-22-2011, 12:09 PM #10 CGTalk Moderation Lord of the posts   Join Date: Sep 2003 Posts: 1,066,481 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. share quote