On Fri, Jun 30, 2006 at 04:24:13PM +0100, Howard Winter wrote: > Peter, > > On Mon, 26 Jun 2006 09:23:18 -0400, Peter Todd wrote: > > >... > > Nah, what I'm really worried about for that wireframe project > > is I have to figure out the math to take a x,y,z reading from an > > acellerometer and convert it into a two part roll (whatever is the > > proper terminology for that) to rotate my wireframe model. > > > > Don't have the clue how I'm going to do it. Don't even know if it's an > > easy problem or a hard one. At least with an education that touched it > > I'd have a vague memory of where to start, even if it took me another 4 > > days to relearn all the details I'd forgotten! > > Isn't it fairly straightforward Trigonometry? Solve the vector for x & y then for this and z? > > Where: > x is the magnitude of the x-axis movement (have to resolve the previous speed and the current acceleration > into a distance moved in a fixed, small, time period) > y is the magnitude of the y-axis movement > z is the magnitude of the z-axis movement I think those definitions are incorrect. x, y, and z are acellerations along their respective axises. However I think to try to integrate them into a distance moved isn't possible. Essentially, take the device and orient it with z perpendicular to gravity. Now rotate it around the x axis. The y value will look like a sign-wave as it's value is essentially something based on sin() So how are you going to know if that is meaning accelleration, or rotation, without a gyroscopic component to directly measure rotation? > By Pythagoras: > > A = SQRT(x^2 + y^2) this is the magnitude of the resultant of x and y. > The angle between this resultant and the x axis is arcTan(y / x) > > B = SQRT(A^2 + z^2) this is the magnitude of the final resultant. > The angle between this and the x-y plane is arcTan(z / A) > > So you now know how far to move (B), and the direction to move (the two angles). You'll have to work out the > signs to get the overall direction right, but a quick test should soon solve that - probably quicker than > thinking it through! :-) As above, if I'm not mistaken your approach may work, but I think only if the orientation of the device is fixed. My problem is the opposite. My intuitive thinking on it is essentially that if I were trying to calculate small angular movements, say +-10degrees on x and y, it'd be some simple trig to convert that into "rotate about x, then rotate about y" angular co-ordinates. But given that I have three coordinates, x, y, z, my intuition tells me that turning that into two values will be tough. Especially given that one of the two value's, y, has a meaning that changes depending on what the other is because of that "rotate about x, *then* rotate about y" meaning. Oh well, I'm sure reading up on more angular coordinate math will help. > Of course, it's over thirty since I did this stuff, but it flashed back to me. Hopefully correctly, but you > never know! :-) As for the matrix calculations, you're on your own - I haven't done those since I was 11... Damn smug and lazy child prodigys! :) -- pete@petertodd.ca http://www.petertodd.ca -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist