From: Ron A. <rr...@ro...> - 2008-01-05 22:29:29
|
I want to add a vector in world relative coordinates to objects in a rotated frame. It first needs to be translated to frame coordinates. I can do this for single axis, but when the frame rotation involves rotation of more than one axis, I can't seem to get it correct. It would be nice to have these three functions ... # The current world_space_function. def frame_to_world_pos(pos, frame): """ Frame position in world space coordinates. """ x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) return frame.pos+pos.x*x_axis+pos.y*y_axis+pos.z*z_axis def world_to_frame_pos(pos, frame): """ World position in frame space coordinates. """ ??? return frame_pos def frame_to_frame_pos(pos, frame1, frame2): """ Frame position in other frame space coordinates. """ wpos = frame_to_world_pos(pos, frame1) return world_to_frame_pos(wpos, frame2) Is there an easy way to move objects from frame to frame and keep their orientation relative to world space? Thanks, Ron |
From: Bruce S. <Bru...@nc...> - 2008-01-05 23:43:43
|
I agree that we need ways to move between frame and scene coordinates. I too have tripped over these missing links. Moving from frame to frame seems to me a rather different and more complex issue. Bruce Sherwood Ron Adam wrote: > I want to add a vector in world relative coordinates to objects in a > rotated frame. It first needs to be translated to frame coordinates. > > I can do this for single axis, but when the frame rotation involves > rotation of more than one axis, I can't seem to get it correct. > > > It would be nice to have these three functions ... > > > # The current world_space_function. > > def frame_to_world_pos(pos, frame): > """ Frame position in world space coordinates. """ > x_axis = norm(frame.axis) > z_axis = norm(cross(frame.axis, frame.up)) > y_axis = norm(cross(z_axis, x_axis)) > return frame.pos+pos.x*x_axis+pos.y*y_axis+pos.z*z_axis > > > def world_to_frame_pos(pos, frame): > """ World position in frame space coordinates. """ > ??? > return frame_pos > > > def frame_to_frame_pos(pos, frame1, frame2): > """ Frame position in other frame space coordinates. """ > wpos = frame_to_world_pos(pos, frame1) > return world_to_frame_pos(wpos, frame2) > > > Is there an easy way to move objects from frame to frame and keep their > orientation relative to world space? > > > Thanks, Ron > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |
From: Ron A. <rr...@ro...> - 2008-01-08 22:08:06
|
Bruce Sherwood wrote: > I agree that we need ways to move between frame and scene coordinates. I > too have tripped over these missing links. > > Moving from frame to frame seems to me a rather different and more > complex issue. After a lot of trial and error, I figured out the following. def frame_to_world_pos(local_pos, frame): """ Frame position in world coordinates. """ x_axis = norm(frame.axis) z_axis = norm(cross(x_axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) x, y, z = local_pos return frame.pos + x * x_axis + y * y_axis + z * z_axis def world_to_frame_pos(world_pos, frame): """ World position in frame coordinates. """ x_axis = norm(frame.axis) z_axis = norm(cross(x_axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) dist = vector(world_pos) - frame.pos return vector(dot(dist, x_axis), dot(dist, y_axis), dot(dist, z_axis)) def frame_to_frame_pos(pos, frame1, frame2): """ Frame position in other frame coordinates. """ wpos = frame_to_world_pos(pos, frame1) return world_to_frame_pos(wpos, frame2) I think with these I can now make some relocate functions that move objects between frames without changing the rotation and position relative to world space. Personally, I'd love to see that feature as methods of shapes and frames. shape.relocate(new_parent_frame) frame.relocate(new_parent_frame) Cheers, Ron > Ron Adam wrote: >> I want to add a vector in world relative coordinates to objects in a >> rotated frame. It first needs to be translated to frame coordinates. >> >> I can do this for single axis, but when the frame rotation involves >> rotation of more than one axis, I can't seem to get it correct. >> >> >> It would be nice to have these three functions ... >> >> >> # The current world_space_function. >> >> def frame_to_world_pos(pos, frame): >> """ Frame position in world space coordinates. """ >> x_axis = norm(frame.axis) >> z_axis = norm(cross(frame.axis, frame.up)) >> y_axis = norm(cross(z_axis, x_axis)) >> return frame.pos+pos.x*x_axis+pos.y*y_axis+pos.z*z_axis >> >> >> def world_to_frame_pos(pos, frame): >> """ World position in frame space coordinates. """ >> ??? >> return frame_pos >> >> >> def frame_to_frame_pos(pos, frame1, frame2): >> """ Frame position in other frame space coordinates. """ >> wpos = frame_to_world_pos(pos, frame1) >> return world_to_frame_pos(wpos, frame2) >> >> >> Is there an easy way to move objects from frame to frame and keep their >> orientation relative to world space? >> >> >> Thanks, Ron >> >> >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2005. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Visualpython-users mailing list >> Vis...@li... >> https://lists.sourceforge.net/lists/listinfo/visualpython-users >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ |
From:
<fre...@gb...> - 2008-01-08 23:24:37
|
On mardi 08 janvier 2008, Ron Adam wrote: > Personally, I'd love to see that feature as methods of shapes and > frames. Well, your are using a OO language ;o) just create a new MyFrame object,=20 from frame, and add the new methods... class MyFrame(frame): def relocate(self, parent): ... =2D-=20 Fr=E9d=E9ric http://www.gbiloba.org |
From: Ron A. <rr...@ro...> - 2008-01-09 17:46:06
|
Frédéric Mantegazza wrote: > On mardi 08 janvier 2008, Ron Adam wrote: > >> Personally, I'd love to see that feature as methods of shapes and >> frames. > > Well, your are using a OO language ;o) just create a new MyFrame object, > from frame, and add the new methods... > > class MyFrame(frame): > def relocate(self, parent): > ... > Yes, that would work for frame, but to be complete, you would also need to do the other 13 objects as My____(). So maybe a general use function would be better after all. <shrug> def reframe(obj, new_frame): ... Still thats only part of the solution for objects with direction attributes such as volocities that also need to be adjusted. Ron |