# Entity rotation using Matrix3

**URL:** <https://community.cesium.com/t/entity-rotation-using-matrix3/7743>\
**Category:** CesiumJS\
**Created:** [November 28, 2018, 6:10pm UTC](https://community.cesium.com/t/entity-rotation-using-matrix3/7743 "2018-11-28T18:10:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umar\_Sharif](https://avatars.discourse-cdn.com/v4/letter/u/bcef8e/32.png) [@Umar\_Sharif](https://community.cesium.com/u/Umar_Sharif)\
**Post date:** [November 28, 2018, 6:10pm UTC](https://community.cesium.com/t/entity-rotation-using-matrix3/7743/1 "2018-11-28T18:10:02Z")

</div>

**I want to rotate a 3d model.**

**I have 3x3 Matrix:**

\<M\_00\>-0.9999982912233401\</M\_00\>

\<M\_01\>-0.001636319085375301\</M\_01\>

\<M\_02\>-0.0008602425863163225\</M\_02\>

\<M\_10\>-0.001631068695467463\</M\_10\>

\<M\_11\>0.9999802528616577\</M\_11\>

\<M\_12\>-0.00606906089589293\</M\_12\>

\<M\_20\>0.0008701565192966738\</M\_20\>

\<M\_21\>-0.006067647409696231\</M\_21\>

\<M\_22\>-0.9999812130648239\</M\_22\>

A 3x3 matrix, using the \<M\_ij\> tags, where M\_ij

denotes the coefficient of the (i+1)th row and the (j+1)th column of the rotation

matrix.

It defines the rotation matrix transforming world

coordinates into camera coordinates (with axes XRightYDown)

Here is my code:

var matrix3 = new Cesium.Matrix3(parseFloat(M\_00), parseFloat(M\_01), parseFloat(M\_02), parseFloat(M\_10), parseFloat(M\_11), parseFloat(M\_12), parseFloat(M\_20), parseFloat(M\_21), parseFloat(M\_22));

var matrix4 = Cesium.Matrix4.fromRotationTranslation(matrix3);

var hpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(matrix4);

var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

var entity = viewer.entities.add({

position: position,

orientation : orientation,

model : {

uri : url,

scale : 0.6

}

});

This does not set the orientation of model. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [November 30, 2018, 4:21pm UTC](https://community.cesium.com/t/entity-rotation-using-matrix3/7743/2 "2018-11-30T16:21:38Z")

</div>

I think it might be simpler here to just use the [quaternion.fromRotationMatrix](https://cesiumjs.org/Cesium/Build/Documentation/Quaternion.html?classFilter=quaternio#.fromRotationMatrix) function directly on your Matrix3. So your code would look something like:

var matrix3 = new Cesium.Matrix3(parseFloat(M\_00), parseFloat(M\_01), parseFloat(M\_02), parseFloat(M\_10), parseFloat(M\_11), parseFloat(M\_12), parseFloat(M\_20), parseFloat(M\_21), parseFloat(M\_22));

var entity = viewer.entities.add({

position: position,

orientation: Cesium.Quaternion.fromRotationMatrix(matrix3),

model : {

uri : url,

scale : 0.6

}

});

Here’s a [running example in Sandcastle](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=lVRba9swFP4rJi9JwZV1sWW7Scu6dg+DjV0KewoMNVYSMVkKkpymLf3vO74kvQxGKhsjnXO+71x0jrfCRVsl76SLziMj76Ir6VVTo1+dbDJedMcra4JQRrpxHD3OTQRLmaX9aHfRWbQU2su4l3qp5SIoaz6bSi1EsO6twVpU9s6DNLjmWWgbXV0aVYsgB9XcPJ1M56Z9thBj4zQEOEYoObyXm41PbkS90fJaBJHUtpLaJ30Cl8oNu9+wRSt9O572TGupVusAZBnGGOHp3sPGetVGDpqhBlfCBdgJw9DS2fparpyUfnJKKEM4T1NOyjhKU4QzzHLM44H65EAJ6Ti1Y68r+7UXTk4xKttV0JJQyliKSRz19fjvAhzGhDPOSImLjOUZew8SFxzTlGYF4DmjNHuXU4J5wcss5XnK2VHIPssC04wWnPAsz493yDEv4VOUWVHSksVHuWtTzDHJeEYAxHnOivgdDnOe5ikueckpI0cAh2ssCCUM87SgrHxuAGmCCvdw//2Ioe6spEeiqibDIBlRtz0PDT54OzTi2WE7aKxTwCBaydm+nX40MDPOgKhr0p+21/ddNhk68GQg6EYEeB+f82qceuW9M1Mwik39Xe2kvlEPbXiEvqxiLXatwc1C6FZJoea41z4d5nZIOTix+COrT/tK9CWZjuLRzId7LS963AdVb6wLbSATmO0gYawhMZ/cNgAPaOF9SztL9qBZpbaRqs7noze/qPkoWmjhPWiWje7in48uZgnYv4JpKyplVt+20mlx35qsycWXXogQmiVw/BcVrNW3wr1g/As).
