Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's assume that you can use the accelerometers to correctly determine which way is 'up'. We can call that vector <strong>N</strong>. It seems to me that you want the 'up' direction of your cube to align with <strong>N</strong>. As already mentioned, that leaves the cube free to spin, but you can still find a rotation matrix that might accomplish what you're going for, but you need to account for two separate cases or else you'll have a singularity in the solution. I'll assume that 'Z' is 'up' on the cube.</p> <p>If you treat the three accelerometer values as a vector and normalize it (to get <strong>N</strong>), you've got the new 'Z' axis portion of your rotation matrix so that a vector pointed in the z direction will now align with the 'up' vector.</p> <pre><code>| a d N.x | |0| |N.x| | b e N.y | * |0| = |N.y| | c f N.z | |1| |N.z| </code></pre> <p>So we need to decide what to do with a-f. One common thing to do is this: if <strong>N</strong> is pointing mostly along the original 'Z' axis, then make the new 'Y' axis portion of the matrix be <strong>M</strong> = <strong>N</strong> cross <strong>X</strong>:</p> <pre><code>d = 0 e = N.z f = -N.y </code></pre> <p>Normalize <strong>M</strong> and then find the 'X' axis portion of the matrix: <strong>L</strong> = <strong>M</strong> cross <strong>N</strong>. Normalize <strong>L</strong>.</p> <p>If <strong>N</strong> is not pointing mostly along the 'Z' axis (N.z &lt; .707), then you find the new 'Y' axis portion as <strong>M</strong> = <strong>N</strong> cross <strong>Z</strong>. Normalize <strong>M</strong> and find <strong>L</strong> = <strong>M</strong> cross <strong>N</strong> and, finally, normalize <strong>L</strong>.</p> <hr> <p>Edit:</p> <p>So we have our three accelerometer values: A.x, A.y, A.z. First step is to normalize them: </p> <pre><code>a = sqrt(A.x*A.x + A.y*Ay + A.z*A.z); and then N.x = A.x/a; N.y = A.y/a; N.z = A.z/a; </code></pre> <p>We assume that if <code>N == [0, 0, 1]</code> then the correct rotation matrix is the identity matrix. If <em>N</em> doesn't point directly along the <em>z-axis</em>, then we want to form a matrix that will rotate the z-axis of the cube so that it lines up with <em>N</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload