0

I would like to know the angular difference between the orientation of two 3D matrices (4x4). Two matrices that are both oriented in the same direction would be zero, and two matrices that are oriented in opposite directions would be 180º. By 'orientation' I am referring to the direction that an object transformed by the matrix would be facing. So I'm only concerned with rotation, not translation or scale.

Specifically, I am using instances of WebKitCSSMatrix which refer to the 16 3D matrix values as .m11 through .m44.

Simon Cave
  • 3,971
  • 4
  • 24
  • 28
  • Even not counting scale and translations there can still be an infinite number of rotational differences in orientation between two matrices whose transformed objects face the same direction. for instance two aircraft whose noses point the same direction but one is flying upside down have different orientations (due to rotation)but face the same direction. Would this still be a "0" in your case? – Steve H Aug 15 '14 at 00:10
  • Yes, it would be. I'm looking for a single angular value between 0º and 180º. Using the analogy of the two aircraft, the roll is immaterial. – Simon Cave Aug 15 '14 at 04:14

1 Answers1

0

in that case compare only one axis from the matrices

  1. extract direction vector from your matrix

    • which one it is depends on your mesh models
    • it is the one the object is going forward
    • in mine models it is usually Z-axis
    • but I also see that other people often use X-axis
    • look here: matrix vectors extraction
    • I am not familiar with your matrix library
    • but there is a chance that your matrices are transposed !!!
    • so if it not works like it should extract the transposed vectors ... (rows instead columns)
  2. compute the difference

    • just compute this: angle = acos ( (V1.V2)/(|V1|.|V2|) )
    • where V1,V2 are the direction vectors
Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380