English subtitles

← Cross Product - Interactive 3D Graphics

Get Embed Code
2 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. For a tilted cylinder we were able to look at and think about what axis to
  2. rotate around. However we usually won't be able to do this. If I gave you two
  3. arbitrary vectors and said quick what's the axis of rotation? Best of luck to
  4. you, I sure couldn't do it. Happily there's an easy way to get the axis of
  5. rotation and it's called the cross product. In three.js you call it like this,
  6. it takes two vectors as its inputs, and the result is put into the vector three
  7. itself. The third vector is in fact the axis of rotation or at least one of
  8. them. The direction is determined by the right hand rule. You wrap your hand
  9. from the first vector, in this case the cylinder to the second vector, in this
  10. case the y axis. This then points along the axis of rotation. If we computed the
  11. cross product of these two vectors in the opposite order we would go from the y
  12. axis to the cylinders vector. And we would get the opposite rotation axis.
  13. Recall how the dot product gives us the cosine between two vectors, the length
  14. of the cross product result is in fact proportional to the sine of the angle
  15. between the two vectors. There is one special case I'm going to point out and
  16. its kind of a headache. If the cross product gives back a vector that is of
  17. length 0 or nearly so then the two vectors are either pointing in the same
  18. direction or in directly opposite directions. You can use the dot product of the
  19. two vectors to figure out which, if they point in the same direction, then
  20. you're done. You don't need to rotate at all. If they point in exactly opposite
  21. directions, then you need to rotate 180 degrees. However, the rotation axis
  22. you'll get back from the cross product is actually 0,0,0, which is no axis at
  23. all. At this point, you basically need to choose some arbitrary axis that is
  24. perpendicular to your vectors and use that for rotation, or just form the
  25. rotation matrix directly. Here for example I use the x axis since I know y is
  26. going to be perpendicular to it. See the additional course materials on a good
  27. way to solve this problem in general. The mathematical notation for a cross
  28. product is this, a big X. The length of the vector produced by the cross product
  29. is equal to the sign of theta, that's the angle between the two vectors, times
  30. the length of A. Times the length of B. The cross product itself is computed by
  31. multiplying neighboring elements of the two vectors' coordinates. For the x
  32. coordinate, we multiply Ay times Bz and then subtract Az times By. For the y
  33. coordinate we multiply Az times Bz minus Ax times Bz. I like to do this kind of
  34. x cross thing here as we did before. So I tend to take this and wrap it around
  35. to this side. So it's Az times Bx, and Ax times Bz. For the last coordinate we
  36. do the same thing, Ax times By minus Ay times Bx. At the end we have a vector
  37. that describes the axis of rotation from one vector to the other. And in fact
  38. this vector will be perpendicular to both of these two. Oh, and one more thing.
  39. If you want to use this vector later you probably going to want to normalize it,
  40. because its length will be pretty obscure.