From: Axawire <ax...@ch...> - 2004-03-14 20:53:13
|
hi i have created a few frame objects and moved them about in the scene and rotated them. if i select an object in a frame how do i get its pos in world co-ordinates (co-ordinates of the whole scene)? thanks rich --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.610 / Virus Database: 390 - Release Date: 3/3/2004 |
From: Jonathan B. <jbr...@ea...> - 2004-03-14 22:13:11
|
On Sun, 2004-03-14 at 15:52, Axawire wrote: > hi > > i have created a few frame objects and moved them about in the scene and > rotated them. if i select an object in a frame how do i get its pos in world > co-ordinates (co-ordinates of the whole scene)? > > thanks > Simple case: the orientation of the frame has not changed (ie, up points along +y and axis points along +x) simply add the object's pos to the frame's pos. Harder case: the orientation of the frame is different. In this case you will need to calculate the unit vectors representing the axes of the frames local coordinate system, and calculate the object's displacement along those unit vectors. # Requirements: # frame has the following attributes: vector pos, vector axis, vector up # (met by all primitive objects in Visual). # local has the following attributes: double x, double y, double z. # (met by vectors and primitive objects in Visual). # frame.axis and frame.up are not colinear. (undefined coordinate # system) def world_space_pos( frame, local): """Returns the position of local in world space.""" x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = cross(z_axis, x_axis)) return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis HTH, -Jonathan Brandmeyer |
From: Jonathan B. <jbr...@ea...> - 2004-03-14 22:15:55
|
On Sun, 2004-03-14 at 17:13, Jonathan Brandmeyer wrote: > On Sun, 2004-03-14 at 15:52, Axawire wrote: > > hi > > > > i have created a few frame objects and moved them about in the scene and > > rotated them. if i select an object in a frame how do i get its pos in world > > co-ordinates (co-ordinates of the whole scene)? > > > > thanks > > > > Simple case: the orientation of the frame has not changed (ie, up points > along +y and axis points along +x) simply add the object's pos to the > frame's pos. > > Harder case: the orientation of the frame is different. In this case > you will need to calculate the unit vectors representing the axes of the > frames local coordinate system, and calculate the object's displacement > along those unit vectors. > > # Requirements: > # frame has the following attributes: vector pos, vector axis, vector up > # (met by all primitive objects in Visual). > # local has the following attributes: double x, double y, double z. > # (met by vectors and primitive objects in Visual). > # frame.axis and frame.up are not colinear. (undefined coordinate > # system) > def world_space_pos( frame, local): > """Returns the position of local in world space.""" > x_axis = norm(frame.axis) > z_axis = norm(cross(frame.axis, frame.up)) > y_axis = cross(z_axis, x_axis)) > return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis > Let me amend that routine. You also have to normalize the y_axis vector (smacks self on head). def world_space_pos( frame, local): """Returns the position of local in world space.""" x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis -Jonathan Brandmeyer |
From: Bruce S. <bas...@un...> - 2004-03-15 02:37:30
|
I've added Jonathan's routine to the on-line documentation for "frame" and also updated the Doc zip file that can be downloaded. Thanks, Jonathan. This does leave open the question however as to whether there ought not be a method in Visual for resolving pos and axis information. In particular, I believe that even Jonathan's routine isn't really complete if this frame is inside another frame: one should really recurse up the enclosing frames. Bruce Sherwood Jonathan Brandmeyer wrote: > Let me amend that routine. You also have to normalize the y_axis vector > (smacks self on head). > > def world_space_pos( frame, local): > """Returns the position of local in world space.""" > x_axis = norm(frame.axis) > z_axis = norm(cross(frame.axis, frame.up)) > y_axis = norm(cross(z_axis, x_axis)) > return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis |
From: Jonathan B. <jdb...@un...> - 2004-03-15 18:43:41
|
Bruce Sherwood wrote: > I've added Jonathan's routine to the on-line documentation for "frame" > and also updated the Doc zip file that can be downloaded. Thanks, > Jonathan. > > This does leave open the question however as to whether there ought > not be a method in Visual for resolving pos and axis information. In > particular, I believe that even Jonathan's routine isn't really > complete if this frame is inside another frame: one should really > recurse up the enclosing frames. > > Bruce Sherwood > How about a pair of member functions of the frame object with the following Python signatures: def world_space_project(self, local): """Returns the vector local in the global coordinate system, following transforms recursively within nested frames.""" def parent_space_project(self, local): """Returns the vector local in the coordinate system of the parent. Iff self.frame==None, this is the same as world_space_project().""" Comments? Questions? -Jonathan Brandmeyer |
From: Jonathan B. <jdb...@un...> - 2004-03-15 18:58:51
|
Bruce Sherwood wrote: > I've added Jonathan's routine to the on-line documentation for "frame" > and also updated the Doc zip file that can be downloaded. Thanks, > Jonathan. > > This does leave open the question however as to whether there ought > not be a method in Visual for resolving pos and axis information. In > particular, I believe that even Jonathan's routine isn't really > complete if this frame is inside another frame: one should really > recurse up the enclosing frames. > > Bruce Sherwood > > Jonathan Brandmeyer wrote: > >> Let me amend that routine. You also have to normalize the y_axis vector >> (smacks self on head). >> >> def world_space_pos( frame, local): >> """Returns the position of local in world space.""" >> x_axis = norm(frame.axis) >> z_axis = norm(cross(frame.axis, frame.up)) >> y_axis = norm(cross(z_axis, x_axis)) >> return frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis > Bruce is right: the above function should be named "parent_space_pos" instead. For completeness, here is what the recursive version would look like, in the event anyone needs it right now: def world_space_pos(frame, local): x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) parent_space = frame.pos + local.x*x_axis + local.y*y_axis + local.z*z_axis if (frame.frame == None): return parent_space else: return world_space_pos(frame.frame, parent_space) |