{
  "id": 124230,
  "title": "Confusion regarding Y,P,R matrices in EULER_to_ROTATION function",
  "url": "/competitions/pku-autonomous-driving/discussion/124230",
  "author_name": "Shashank",
  "post_date": "2020-01-02T19:22:15.590000",
  "votes": 2,
  "comment_count": 6,
  "views": 0,
  "content": "<p>```python\nfrom math import sin, cos</p>\n\n<h1>convert euler angle to rotation matrix</h1>\n\n<p>def euler_to_Rot(yaw, pitch, roll):\n    Y = np.array([[cos(yaw), 0, sin(yaw)],\n                  [0, 1, 0],\n                  [-sin(yaw), 0, cos(yaw)]])\n    P = np.array([[1, 0, 0],\n                  [0, cos(pitch), -sin(pitch)],\n                  [0, sin(pitch), cos(pitch)]])\n    R = np.array([[cos(roll), -sin(roll), 0],\n                  [sin(roll), cos(roll), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```</p>\n\n<p>Acc to this discussion <a href=\"https://www.kaggle.com/c/pku-autonomous-driving/discussion/123385\">Link</a> , the above matrices Y, P are incorrect, however, changing those values and plotting bounding boxes results in wrong visualization. </p>\n\n<p>Can, anybody explain (or give reference material) the theory behind this function, including the dot product in return statement ( cell no.20 in <a href=\"https://www.kaggle.com/hocop1/centernet-baseline\">this</a> notebook )</p>",
  "messages": [
    {
      "id": 708861,
      "postDate": "2020-01-02T19:22:15.590Z",
      "content": "<p>```python\nfrom math import sin, cos</p>\n\n<h1>convert euler angle to rotation matrix</h1>\n\n<p>def euler_to_Rot(yaw, pitch, roll):\n    Y = np.array([[cos(yaw), 0, sin(yaw)],\n                  [0, 1, 0],\n                  [-sin(yaw), 0, cos(yaw)]])\n    P = np.array([[1, 0, 0],\n                  [0, cos(pitch), -sin(pitch)],\n                  [0, sin(pitch), cos(pitch)]])\n    R = np.array([[cos(roll), -sin(roll), 0],\n                  [sin(roll), cos(roll), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```</p>\n\n<p>Acc to this discussion <a href=\"https://www.kaggle.com/c/pku-autonomous-driving/discussion/123385\">Link</a> , the above matrices Y, P are incorrect, however, changing those values and plotting bounding boxes results in wrong visualization. </p>\n\n<p>Can, anybody explain (or give reference material) the theory behind this function, including the dot product in return statement ( cell no.20 in <a href=\"https://www.kaggle.com/hocop1/centernet-baseline\">this</a> notebook )</p>",
      "rawMarkdown": "\n\n```python\nfrom math import sin, cos\n\n# convert euler angle to rotation matrix\ndef euler_to_Rot(yaw, pitch, roll):\n    Y = np.array([[cos(yaw), 0, sin(yaw)],\n                  [0, 1, 0],\n                  [-sin(yaw), 0, cos(yaw)]])\n    P = np.array([[1, 0, 0],\n                  [0, cos(pitch), -sin(pitch)],\n                  [0, sin(pitch), cos(pitch)]])\n    R = np.array([[cos(roll), -sin(roll), 0],\n                  [sin(roll), cos(roll), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```\n\nAcc to this discussion [Link](https://www.kaggle.com/c/pku-autonomous-driving/discussion/123385) , the above matrices Y, P are incorrect, however, changing those values and plotting bounding boxes results in wrong visualization. \n\nCan, anybody explain (or give reference material) the theory behind this function, including the dot product in return statement ( cell no.20 in [this](https://www.kaggle.com/hocop1/centernet-baseline) notebook )",
      "votes": 2
    },
    {
      "id": 1295331,
      "postDate": "2021-05-06T11:33:56.580Z",
      "content": "<p>hi,may i ask did u solve these two questions of u?cuz i have the same questions just like u now and i didnt find answers</p>",
      "rawMarkdown": "hi,may i ask did u solve these two questions of u?cuz i have the same questions just like u now and i didnt find answers"
    },
    {
      "id": 709086,
      "postDate": "2020-01-03T03:07:35.037Z",
      "content": "<p>This formula is right, hocop1 have exchanged yaw and pitch. Sorry if my discussion confuse you.\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3876174%2F59f325f2f37eb2e96a2c68528393beac%2F2020-01-03_105730.png?generation=1578020300141607&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "This formula is right, hocop1 have exchanged yaw and pitch. Sorry if my discussion confuse you.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3876174%2F59f325f2f37eb2e96a2c68528393beac%2F2020-01-03_105730.png?generation=1578020300141607&amp;alt=media)",
      "replies": [
        {
          "id": 709675,
          "postDate": "2020-01-03T20:07:12.320Z",
          "content": "<p><a href=\"/diegojohnson\">@diegojohnson</a> yes, i am aware that pitch. yaw have been exchanged. What I am trying to understand is:</p>\n\n<p>(1) the theoretical logic behind how the 3 matrices have been made, and \n(2)the physical significance of their dot product for this competition (I can't get the intuition right, don't want to just copy-paste code). </p>\n\n<p>I have read up on euler angles, rotation from multiple sources. Generally, roll-&gt;x axis, pitch-&gt;y axis, yaw-&gt;z axis.  In above matrices, it seems roll-&gt;z axis, pitch-&gt;x axis, yaw-&gt;y axis. (also, these are camera axis, right?)\nAlso, were the axes direction in the 2nd image of your discussion correct? Acc to me, they are; after analyzing some images and the 6 values of different cars, i came to the same conclusion.\nWhat I am trying to understand is that instead of the above, why not this: \n```python\nfrom math import sin, cos</p>\n\n<h1>convert euler angle to rotation matrix</h1>\n\n<p>def euler_to_Rot(yaw, pitch, roll):\n    P = np.array([[cos(pitch), 0, sin(pitch)],\n                  [0, 1, 0],\n                  [-sin(pitch), 0, cos(pitch)]])\n    R = np.array([[1, 0, 0],\n                  [0, cos(roll), -sin(roll)],\n                  [0, sin(roll), cos(roll)]])\n    Y = np.array([[cos(yaw), -sin(yaw), 0],\n                  [sin(yaw), cos(yaw), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```\nI hope you're getting my confusion. Mainly 2 of them(listed above). If the theoretical explanation is too long, then I would appreciate if you've any reference material/link.\nThanks🙂</p>",
          "rawMarkdown": "@diegojohnson yes, i am aware that pitch. yaw have been exchanged. What I am trying to understand is:\n\n(1) the theoretical logic behind how the 3 matrices have been made, and \n(2)the physical significance of their dot product for this competition (I can't get the intuition right, don't want to just copy-paste code). \n\nI have read up on euler angles, rotation from multiple sources. Generally, roll-&gt;x axis, pitch-&gt;y axis, yaw-&gt;z axis.  In above matrices, it seems roll-&gt;z axis, pitch-&gt;x axis, yaw-&gt;y axis. (also, these are camera axis, right?)\nAlso, were the axes direction in the 2nd image of your discussion correct? Acc to me, they are; after analyzing some images and the 6 values of different cars, i came to the same conclusion.\nWhat I am trying to understand is that instead of the above, why not this: \n```python\nfrom math import sin, cos\n\n# convert euler angle to rotation matrix\ndef euler_to_Rot(yaw, pitch, roll):\n    P = np.array([[cos(pitch), 0, sin(pitch)],\n                  [0, 1, 0],\n                  [-sin(pitch), 0, cos(pitch)]])\n    R = np.array([[1, 0, 0],\n                  [0, cos(roll), -sin(roll)],\n                  [0, sin(roll), cos(roll)]])\n    Y = np.array([[cos(yaw), -sin(yaw), 0],\n                  [sin(yaw), cos(yaw), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```\nI hope you're getting my confusion. Mainly 2 of them(listed above). If the theoretical explanation is too long, then I would appreciate if you've any reference material/link.\nThanks🙂",
          "votes": 1
        },
        {
          "id": 709903,
          "postDate": "2020-01-04T03:56:16.857Z",
          "content": "<p>sorry, I think your formula is wrong. \nfor example, Y * [x, y, z].T = [[cos(yaw)*x + sin(yaw)*z,\n                                                  y,\n                                                  ...]]\nit means the dot (x,y,z) don't change y-axis in yaw, because yaw is a transform around the y-axis. \nYou can transfrom the matrix to polynomial to see how it work.\ngive me an upvote, if you think it's useful.😀 \n<a href=\"/iamshshnk\">@iamshshnk</a> </p>",
          "rawMarkdown": "sorry, I think your formula is wrong. \nfor example, Y * [x, y, z].T = [[cos(yaw)*x + sin(yaw)*z,\n                                                  y,\n                                                  ...]]\nit means the dot (x,y,z) don't change y-axis in yaw, because yaw is a transform around the y-axis. \nYou can transfrom the matrix to polynomial to see how it work.\ngive me an upvote, if you think it's useful.😀 \n@iamshshnk "
        }
      ]
    },
    {
      "id": 708863,
      "postDate": "2020-01-02T19:26:14.317Z",
      "content": "<p><a href=\"/diegojohnson\">@diegojohnson</a> I have referred to your discussion here. Am I interpreting it correctly?\n<a href=\"/hocop1\">@hocop1</a> what reasoning have you applied in this function? \nThanks to both for your notebooks+discussions 👌.</p>",
      "rawMarkdown": "@diegojohnson I have referred to your discussion here. Am I interpreting it correctly?\n@hocop1 what reasoning have you applied in this function? \nThanks to both for your notebooks+discussions 👌.\n",
      "replies": [
        {
          "id": 708865,
          "postDate": "2020-01-02T19:27:14.040Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1295331,
      "author_name": "martinlee07",
      "author_url": "",
      "post_date": "2021-05-06T11:33:56.580000",
      "content": "<p>hi,may i ask did u solve these two questions of u?cuz i have the same questions just like u now and i didnt find answers</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 709086,
      "author_name": "DiegoJohnson",
      "author_url": "",
      "post_date": "2020-01-03T03:07:35.037000",
      "content": "<p>This formula is right, hocop1 have exchanged yaw and pitch. Sorry if my discussion confuse you.\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3876174%2F59f325f2f37eb2e96a2c68528393beac%2F2020-01-03_105730.png?generation=1578020300141607&amp;alt=media\" alt=\"\"></p>",
      "votes": 0,
      "replies": [
        {
          "id": 709675,
          "author_name": "Shashank",
          "author_url": "",
          "post_date": "2020-01-03T20:07:12.320000",
          "content": "<p><a href=\"/diegojohnson\">@diegojohnson</a> yes, i am aware that pitch. yaw have been exchanged. What I am trying to understand is:</p>\n\n<p>(1) the theoretical logic behind how the 3 matrices have been made, and \n(2)the physical significance of their dot product for this competition (I can't get the intuition right, don't want to just copy-paste code). </p>\n\n<p>I have read up on euler angles, rotation from multiple sources. Generally, roll-&gt;x axis, pitch-&gt;y axis, yaw-&gt;z axis.  In above matrices, it seems roll-&gt;z axis, pitch-&gt;x axis, yaw-&gt;y axis. (also, these are camera axis, right?)\nAlso, were the axes direction in the 2nd image of your discussion correct? Acc to me, they are; after analyzing some images and the 6 values of different cars, i came to the same conclusion.\nWhat I am trying to understand is that instead of the above, why not this: \n```python\nfrom math import sin, cos</p>\n\n<h1>convert euler angle to rotation matrix</h1>\n\n<p>def euler_to_Rot(yaw, pitch, roll):\n    P = np.array([[cos(pitch), 0, sin(pitch)],\n                  [0, 1, 0],\n                  [-sin(pitch), 0, cos(pitch)]])\n    R = np.array([[1, 0, 0],\n                  [0, cos(roll), -sin(roll)],\n                  [0, sin(roll), cos(roll)]])\n    Y = np.array([[cos(yaw), -sin(yaw), 0],\n                  [sin(yaw), cos(yaw), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```\nI hope you're getting my confusion. Mainly 2 of them(listed above). If the theoretical explanation is too long, then I would appreciate if you've any reference material/link.\nThanks🙂</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 709903,
          "author_name": "DiegoJohnson",
          "author_url": "",
          "post_date": "2020-01-04T03:56:16.857000",
          "content": "<p>sorry, I think your formula is wrong. \nfor example, Y * [x, y, z].T = [[cos(yaw)*x + sin(yaw)*z,\n                                                  y,\n                                                  ...]]\nit means the dot (x,y,z) don't change y-axis in yaw, because yaw is a transform around the y-axis. \nYou can transfrom the matrix to polynomial to see how it work.\ngive me an upvote, if you think it's useful.😀 \n<a href=\"/iamshshnk\">@iamshshnk</a> </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 708863,
      "author_name": "Shashank",
      "author_url": "",
      "post_date": "2020-01-02T19:26:14.317000",
      "content": "<p><a href=\"/diegojohnson\">@diegojohnson</a> I have referred to your discussion here. Am I interpreting it correctly?\n<a href=\"/hocop1\">@hocop1</a> what reasoning have you applied in this function? \nThanks to both for your notebooks+discussions 👌.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 708865,
          "author_name": "",
          "author_url": "",
          "post_date": "2020-01-02T19:27:14.040000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "708861": "\n\n```python\nfrom math import sin, cos\n\n# convert euler angle to rotation matrix\ndef euler_to_Rot(yaw, pitch, roll):\n    Y = np.array([[cos(yaw), 0, sin(yaw)],\n                  [0, 1, 0],\n                  [-sin(yaw), 0, cos(yaw)]])\n    P = np.array([[1, 0, 0],\n                  [0, cos(pitch), -sin(pitch)],\n                  [0, sin(pitch), cos(pitch)]])\n    R = np.array([[cos(roll), -sin(roll), 0],\n                  [sin(roll), cos(roll), 0],\n                  [0, 0, 1]])\n    return np.dot(Y, np.dot(P, R))\n```\n\nAcc to this discussion [Link](https://www.kaggle.com/c/pku-autonomous-driving/discussion/123385) , the above matrices Y, P are incorrect, however, changing those values and plotting bounding boxes results in wrong visualization. \n\nCan, anybody explain (or give reference material) the theory behind this function, including the dot product in return statement ( cell no.20 in [this](https://www.kaggle.com/hocop1/centernet-baseline) notebook )",
    "1295331": "hi,may i ask did u solve these two questions of u?cuz i have the same questions just like u now and i didnt find answers",
    "709086": "This formula is right, hocop1 have exchanged yaw and pitch. Sorry if my discussion confuse you.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3876174%2F59f325f2f37eb2e96a2c68528393beac%2F2020-01-03_105730.png?generation=1578020300141607&amp;alt=media)",
    "708863": "@diegojohnson I have referred to your discussion here. Am I interpreting it correctly?\n@hocop1 what reasoning have you applied in this function? \nThanks to both for your notebooks+discussions 👌.\n"
  }
}