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/ |