1. <small id='7TyFc'></small><noframes id='7TyFc'>

        <legend id='7TyFc'><style id='7TyFc'><dir id='7TyFc'><q id='7TyFc'></q></dir></style></legend>
        <tfoot id='7TyFc'></tfoot>
        • <bdo id='7TyFc'></bdo><ul id='7TyFc'></ul>
      2. <i id='7TyFc'><tr id='7TyFc'><dt id='7TyFc'><q id='7TyFc'><span id='7TyFc'><b id='7TyFc'><form id='7TyFc'><ins id='7TyFc'></ins><ul id='7TyFc'></ul><sub id='7TyFc'></sub></form><legend id='7TyFc'></legend><bdo id='7TyFc'><pre id='7TyFc'><center id='7TyFc'></center></pre></bdo></b><th id='7TyFc'></th></span></q></dt></tr></i><div id='7TyFc'><tfoot id='7TyFc'></tfoot><dl id='7TyFc'><fieldset id='7TyFc'></fieldset></dl></div>

        C++:围绕某个点旋转向量

        时间:2023-09-15
        <i id='9VUZH'><tr id='9VUZH'><dt id='9VUZH'><q id='9VUZH'><span id='9VUZH'><b id='9VUZH'><form id='9VUZH'><ins id='9VUZH'></ins><ul id='9VUZH'></ul><sub id='9VUZH'></sub></form><legend id='9VUZH'></legend><bdo id='9VUZH'><pre id='9VUZH'><center id='9VUZH'></center></pre></bdo></b><th id='9VUZH'></th></span></q></dt></tr></i><div id='9VUZH'><tfoot id='9VUZH'></tfoot><dl id='9VUZH'><fieldset id='9VUZH'></fieldset></dl></div>
      3. <legend id='9VUZH'><style id='9VUZH'><dir id='9VUZH'><q id='9VUZH'></q></dir></style></legend>
        <tfoot id='9VUZH'></tfoot>
            <bdo id='9VUZH'></bdo><ul id='9VUZH'></ul>

                <tbody id='9VUZH'></tbody>

                <small id='9VUZH'></small><noframes id='9VUZH'>

                1. 本文介绍了C++:围绕某个点旋转向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试围绕向量上的某个点旋转向量(在 C++ 中):

                  I am trying to rotate a vector around a certain point on the vector(in C++):

                  1 2 3
                  4 5 6
                  7 8 9
                  

                  围绕点 (1,1)(即5")旋转 90 度将导致:

                  rotated around the point (1,1) (which is the "5") 90 degrees would result in:

                  7 4 1
                  8 5 2
                  9 6 3
                  

                  现在我正在使用:

                  x = (x * cos(90)) - (y * sin(90))
                  y = (y * cos(90)) + (x * sin(90))
                  

                  但我不希望它围绕 (0,0) 旋转

                  But I don't want it rotated around (0,0)

                  推荐答案

                  答案取决于您的坐标系.

                  The answer depends on your coordinate system.

                  如果您使用计算机图形矢量实现,其中 (0,0)左上角,并且您正在围绕点 (dx,dy),那么旋转计算,包括转换回原始坐标系,将是:

                  If you are using a computer graphics vector implementation where (0,0) is the top left corner and you are rotating around the point (dx, dy), then the rotation calculation, including the translation back into the original coordinate system, would be:

                  x_rotated =      ((x - dx) * cos(angle)) - ((dy - y) * sin(angle)) + dx
                  y_rotated = dy - ((dy - y) * cos(angle)) + ((x - dx) * sin(angle))
                  

                  物理/数学坐标系,(0,0)位于底部左侧

                  如果您使用的是更传统的现实世界坐标系,其中(0,0)左角,然后旋转计算,围绕点(dx, dy) 包括转换回原始坐标系,将是:

                  Physics/Maths coordinate system, with (0,0) at Bottom left

                  If you are using a more traditional real world coordinate system, where (0,0) is the bottom left corner, then the rotation calculation, around the point (dx, dy) including the translation back into the original coordinate system, would be:

                  x_rotated = ((x - dx) * cos(angle)) - ((y - dy) * sin(angle)) + dx
                  y_rotated = ((x - dx) * sin(angle)) + ((y - dy) * cos(angle)) + dy
                  

                  感谢 mmx 对 Pesto 的帖子,以及 SkeletorFromEterenia 以突出显示我的实施中的错误.

                  Thanks to mmx for their comment on Pesto's post, and to SkeletorFromEterenia for highlighting an error in my implementation.

                  这篇关于C++:围绕某个点旋转向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:无法从基类类型的指针访问派生类方法 下一篇:std::vector 何时重新分配其内存数组?

                  相关文章

                  最新文章

                    <small id='iRxus'></small><noframes id='iRxus'>

                  1. <i id='iRxus'><tr id='iRxus'><dt id='iRxus'><q id='iRxus'><span id='iRxus'><b id='iRxus'><form id='iRxus'><ins id='iRxus'></ins><ul id='iRxus'></ul><sub id='iRxus'></sub></form><legend id='iRxus'></legend><bdo id='iRxus'><pre id='iRxus'><center id='iRxus'></center></pre></bdo></b><th id='iRxus'></th></span></q></dt></tr></i><div id='iRxus'><tfoot id='iRxus'></tfoot><dl id='iRxus'><fieldset id='iRxus'></fieldset></dl></div>

                    <legend id='iRxus'><style id='iRxus'><dir id='iRxus'><q id='iRxus'></q></dir></style></legend>

                      <bdo id='iRxus'></bdo><ul id='iRxus'></ul>

                    <tfoot id='iRxus'></tfoot>