English 中文(简体)
Finding the spin of a sphere given X, Y, and Z vectors relative to sphere
原标题:

I m using Electro in Lua for some 3D simulations, and I m running in to something of a mathematical/algorithmic/physics snag.

I m trying to figure out how I would find the "spin" of a sphere of a sphere that is spinning on some axis. By "spin" I mean a vector along the axis that the sphere is spinning on with a magnitude relative to the speed at which it is spinning. The reason I need this information is to be able to slow down the spin of the sphere by applying reverse torque to the sphere until it stops spinning.

The only information I have access to is the X, Y, and Z unit vectors relative to the sphere. That is, each frame, I can call three different functions, each of which returns a unit vector pointing in the direction of the sphere model s local X, Y and Z axes, respectively. I can keep track of how each of these change by essentially keeping the "previous" value of each vector and comparing it to the "new" value each frame. The question, then, is how would I use this information to determine the sphere s spin? I m stumped.

Any help would be great. Thanks!

最佳回答

My first answer was wrong. This is my edited answer.

Your unit vectors X,Y,Z can be put together to form a 3x3 matrix:

A = [[x1 y1 z1],
     [x2 y2 z2],
     [x3 y3 z3]]

Since X,Y,Z change with time, A also changes with time.

A is a rotation matrix! After all, if you let i=(1,0,0) be the unit vector along the x-axis, then A i = X so A rotates i into X. Similarly, it rotates the y-axis into Y and the z-axis into Z.

A is called the direction cosine matrix (DCM).

So using the DCM to Euler axis formula

Compute

theta = arccos((A_11 + A_22 + A_33 - 1)/2)

theta is the Euler angle of rotation.

The magnitude of the angular velocity, |w|, equals

w = d(theta)/dt ~= (theta(t+dt)-theta(t)) / dt

The axis of rotation is given by e = (e1,e2,e3) where

e1 = (A_32 - A_23)/(2 sin(theta))
e2 = (A_13 - A_31)/(2 sin(theta))
e3 = (A_21 - A_12)/(2 sin(theta))
问题回答

I applaud ~unutbu s, answer, but I think there s a simpler approach that will suffice for this problem.

Take the X unit vector at three successive frames, and compare them to get two deltas:

deltaX1 = X2 - X1
deltaX2 = X3 - X2

(These are vector equations. X1 is a vector, the X vector at time 1, not a number.)

Now take the cross-product of the deltas and you ll get a vector in the direction of the rotation vector.

Now for the magnitude. The angle between the two deltas is the angle swept out in one time interval, so use the dot product:

dx1 = deltaX1/|deltaX1|
dx2 = deltax2/|deltaX2|
costheta = dx1.dx2
theta = acos(costheta)
w = theta/dt

For the sake of precision you should choose the unit vector (X, Y or Z) that changes the most.





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签