From: Tony R. <To...@br...> - 2009-08-04 04:48:33
|
Thanks for some direction! I managed to get a routine that works for what I wanted; my frame is not shifted away from (0,0,0), and is only rotating on the Y-axis so is probably why this works: def local_space_pos(frame, world): """Returns the position of world in local space.""" origin = visual.vector(1,0,0) axis = visual.cross(frame.axis, origin) theta = frame.axis.diff_angle(origin) trans = visual.vector(world.pos) trans = visual.rotate(trans, angle=theta, axis=axis) return trans I tried some other variations of this, as well as some based of the example on the docs, but none really worked. I think I understand the math for the most part and am more confused about the properties I'm actually using. I could make a function that updates the *.pos directly in the global frame, using all three dimensions, and forget about the local one, but it seems much simpler/cleaner, especially since the frame will contain many objects, to let the frame rotate and push the objects around with simple "shoves"/vectors in a single dimension -- producing a nice helix effect. I looked into the quaternions and friends, and may come back on this if I do decide i want/need an arbitrary method. The rotating is really more eye/shock candy than anything else for this log visualizer I'm constructing, and as my first dabble in python I'm trying to just get the thing rolling, then I'll come back and give the thing pluggable engines and whatnot :-) Thanks again, C Anthony ________________________________________ From: Jim Thomas [jt...@mi...] Sent: Tuesday, July 28, 2009 11:41 AM To: vis...@li... Subject: Re: [Visualpython-users] Arbitrary frame transformation routine I don't have an easy code solution that I can share right now but I can give you some pointers. Firstly quaternions can be used to do this type of thing so you might want to read up on that. A quaternion can be constructed to represent the orientation of each frame and then you can do operations using them to perform rotations between frames. This is how I normally handle a problem like yours. Also visual has a rotate function which you could use. You can transform the position of a point using a series of rotations (after first subtracting the difference of the frame origins). The example you site shows how to get x,y, and z axes from the axis and up vectors that visual uses. Then for each axis you perform a rotation (in series). The axis about which you rotate is computed using the cross product (cross(f1.x, f2.x)) and the angle is computed using the dot product (acos(dot(f1.x, f2.x)). Rotate your point vector then repeat for y and z. You must trap for the condition where the magnitude of the cross product is near zero, in which case you skip that rotation step since they are already aligned. There is probably a shortcut along the lines of what the example does but I have not worked it out. Also if you were working with something asymmetric rather than a sphere you would have to do transformations on axis and up for the object as well. Hope this helps at least a little bit. I have code that will do this but it is in no condition for me to publish at this time and I cannot extract a snippet that will help you, I'd have to release a whole lot of code. I guess I need to work on getting my library for visual python out the door... JT PS There are a couple of quaternion functions in the odelib portion of my VisualPyODE library that I have released. Unfortunately it is probably not enough to be a big help but if you are interested download the code at http://www.missioncognition.net. For that library ODE is the owner of the coordinates/orientations and I just slave the visual objects off of them. Still you might find some of code informative. Tony Risinger wrote: > I have been trying to no avail to write a routine to transform the coordinates of vector from the global frame to a local one; or even better would be a routine that transforms from one arbitrary frame to another (then global frame is just pos(0,0,0) and axis(1,0,0)). the example in the documentation translates from local-to-global, but i cant seem to reverse it. seems that my vector skills are weak... > > in this log file visualizer i am working on, i have a sphere traveling thru the global frame, but at a specified point, or at init, i want to inject it into a rotating local frame. i want the switch to the localized frame to appear seamless, thus i need to get the local coordinates relative to the global ones the sphere currently has. > > is functionality of this type already present somewhere in the module but im missing it? once i apply a frame to an object it immediately moves the coordinates it currently has but relative to the local frame, so it appears to jump thru space. this is great and expected, i just need to get the switchover down now. > > does anyone have something whipped up already that you could kindly share? otherwise direction of any kind would be greatly appreciated. > > Thanks, > > Tony Risinger > Application Development Specialist > Tel: 507-535-7563 | Fax: 507-292-5747 | Toll Free: 866-241-0639 > > To...@Br... > > http://www.brokerbin.com/ > > CONFIDENTIAL INFORMATION: This electronic mail message and any attached files contain information intended for the exclusive use of the specific individual(s) or entity(s) to whom it is addressed and may contain information that is propriety, privileged or confidential or otherwise exempt from disclosure. If you are not the intended recipient, please notify the sender immediately, by reply electronic mail or by telephone, of any unintended recipients so we may correct our records. Also, delete the original electronic mail and any attachments without making any copies of the electronic mail message or attachments. > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Visualpython-users mailing list Vis...@li... https://lists.sourceforge.net/lists/listinfo/visualpython-users Tony Risinger Application Development Specialist Tel: 507-535-7563 | Fax: 507-292-5747 | Toll Free: 866-241-0639 To...@Br... http://www.brokerbin.com/ CONFIDENTIAL INFORMATION: This electronic mail message and any attached files contain information intended for the exclusive use of the specific individual(s) or entity(s) to whom it is addressed and may contain information that is propriety, privileged or confidential or otherwise exempt from disclosure. If you are not the intended recipient, please notify the sender immediately, by reply electronic mail or by telephone, of any unintended recipients so we may correct our records. Also, delete the original electronic mail and any attachments without making any copies of the electronic mail message or attachments. |