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

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

      <legend id='GnUcO'><style id='GnUcO'><dir id='GnUcO'><q id='GnUcO'></q></dir></style></legend>
    1. <tfoot id='GnUcO'></tfoot>
    2. <i id='GnUcO'><tr id='GnUcO'><dt id='GnUcO'><q id='GnUcO'><span id='GnUcO'><b id='GnUcO'><form id='GnUcO'><ins id='GnUcO'></ins><ul id='GnUcO'></ul><sub id='GnUcO'></sub></form><legend id='GnUcO'></legend><bdo id='GnUcO'><pre id='GnUcO'><center id='GnUcO'></center></pre></bdo></b><th id='GnUcO'></th></span></q></dt></tr></i><div id='GnUcO'><tfoot id='GnUcO'></tfoot><dl id='GnUcO'><fieldset id='GnUcO'></fieldset></dl></div>
    3. 在矩形中旋转点

      时间:2023-10-13
          • <bdo id='XEelo'></bdo><ul id='XEelo'></ul>

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

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

              • <tfoot id='XEelo'></tfoot>
                <legend id='XEelo'><style id='XEelo'><dir id='XEelo'><q id='XEelo'></q></dir></style></legend>

              • 本文介绍了在矩形中旋转点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在一个矩形中有一个点,我需要旋转任意角度并找到该点的 x y.我如何使用 javascript 来做到这一点.

                I have a point in a rectangle that I need to rotate an arbitrary degree and find the x y of the point. How can I do this using javascript.

                在 x,y 下方会是 1,3,在我将 90 传递给方法后,它将返回 3,1.

                Below the x,y would be something like 1,3 and after I pass 90 into the method it will return 3,1.

                |-------------|
                |  *          |
                |             |
                |             |
                |-------------|
                 _____
                |    *|
                |     |
                |     |
                |     |
                |     |
                 _____
                
                |-------------|
                |             |
                |             |
                |            *|
                |-------------|
                 _____
                |     |
                |     |
                |     |
                |     |
                |*    |
                 _____
                

                基本上我正在寻找这种方法的勇气

                Basically I am looking for the guts to this method

                function Rotate(pointX,pointY,rectWidth,rectHeight,angle){
                   /*magic*/    
                   return {newX:x,newY:y};
                }
                

                推荐答案

                应该这样做:

                function Rotate(pointX, pointY, rectWidth, rectHeight, angle) {
                  // convert angle to radians
                  angle = angle * Math.PI / 180.0
                  // calculate center of rectangle
                  var centerX = rectWidth / 2.0;
                  var centerY = rectHeight / 2.0;
                  // get coordinates relative to center
                  var dx = pointX - centerX;
                  var dy = pointY - centerY;
                  // calculate angle and distance
                  var a = Math.atan2(dy, dx);
                  var dist = Math.sqrt(dx * dx + dy * dy);
                  // calculate new angle
                  var a2 = a + angle;
                  // calculate new coordinates
                  var dx2 = Math.cos(a2) * dist;
                  var dy2 = Math.sin(a2) * dist;
                  // return coordinates relative to top left corner
                  return { newX: dx2 + centerX, newY: dy2 + centerY };
                }
                

                这篇关于在矩形中旋转点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:用CSS将所有html元素(整个页面)旋转90度? 下一篇:为什么div和旋转的div(三角形)之间有间隙

                相关文章

                最新文章

                • <bdo id='GyLIL'></bdo><ul id='GyLIL'></ul>
              • <small id='GyLIL'></small><noframes id='GyLIL'>

              • <legend id='GyLIL'><style id='GyLIL'><dir id='GyLIL'><q id='GyLIL'></q></dir></style></legend><tfoot id='GyLIL'></tfoot>

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