• <bdo id='em0Ks'></bdo><ul id='em0Ks'></ul>

    1. <i id='em0Ks'><tr id='em0Ks'><dt id='em0Ks'><q id='em0Ks'><span id='em0Ks'><b id='em0Ks'><form id='em0Ks'><ins id='em0Ks'></ins><ul id='em0Ks'></ul><sub id='em0Ks'></sub></form><legend id='em0Ks'></legend><bdo id='em0Ks'><pre id='em0Ks'><center id='em0Ks'></center></pre></bdo></b><th id='em0Ks'></th></span></q></dt></tr></i><div id='em0Ks'><tfoot id='em0Ks'></tfoot><dl id='em0Ks'><fieldset id='em0Ks'></fieldset></dl></div>
    2. <legend id='em0Ks'><style id='em0Ks'><dir id='em0Ks'><q id='em0Ks'></q></dir></style></legend>
    3. <small id='em0Ks'></small><noframes id='em0Ks'>

      1. <tfoot id='em0Ks'></tfoot>

        返回两个圆之间的 x,y 交点的 JavaScript 函数?

        时间:2023-09-07

        <tfoot id='OT132'></tfoot>
          <bdo id='OT132'></bdo><ul id='OT132'></ul>

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

                <tbody id='OT132'></tbody>

            • <legend id='OT132'><style id='OT132'><dir id='OT132'><q id='OT132'></q></dir></style></legend>

              <i id='OT132'><tr id='OT132'><dt id='OT132'><q id='OT132'><span id='OT132'><b id='OT132'><form id='OT132'><ins id='OT132'></ins><ul id='OT132'></ul><sub id='OT132'></sub></form><legend id='OT132'></legend><bdo id='OT132'><pre id='OT132'><center id='OT132'></center></pre></bdo></b><th id='OT132'></th></span></q></dt></tr></i><div id='OT132'><tfoot id='OT132'></tfoot><dl id='OT132'><fieldset id='OT132'></fieldset></dl></div>
                1. 本文介绍了返回两个圆之间的 x,y 交点的 JavaScript 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  I got the (x,y) center location of two circles and their radius but I need to find their intersection points (marked with red) using JavaScript.

                  I think the best explanation as far as the math is concerned is found here (Intersection of two circles), but I don't really understand the math so I'm not able to implement it.

                  For example d = ||P1 - P0|| , what do the || stand for? Does it mean that the resulting number is always a positive?

                  And also P2 = P0 + a ( P1 - P0 ) / d , aren't the P's here something like (10, 50)? But doing (10,50)+13 in JavaScript gives you 63, so it just ignores the first number, so what's suppose to happen? Should the outcome be (23,63) here or? And also the P1-P0 part or (40,30)-(10,60), how do you express that in JavaScript?

                  解决方案

                  Translated the C function on the site to JavaScript:

                  function intersection(x0, y0, r0, x1, y1, r1) {
                          var a, dx, dy, d, h, rx, ry;
                          var x2, y2;
                  
                          /* dx and dy are the vertical and horizontal distances between
                           * the circle centers.
                           */
                          dx = x1 - x0;
                          dy = y1 - y0;
                  
                          /* Determine the straight-line distance between the centers. */
                          d = Math.sqrt((dy*dy) + (dx*dx));
                  
                          /* Check for solvability. */
                          if (d > (r0 + r1)) {
                              /* no solution. circles do not intersect. */
                              return false;
                          }
                          if (d < Math.abs(r0 - r1)) {
                              /* no solution. one circle is contained in the other */
                              return false;
                          }
                  
                          /* 'point 2' is the point where the line through the circle
                           * intersection points crosses the line between the circle
                           * centers.  
                           */
                  
                          /* Determine the distance from point 0 to point 2. */
                          a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
                  
                          /* Determine the coordinates of point 2. */
                          x2 = x0 + (dx * a/d);
                          y2 = y0 + (dy * a/d);
                  
                          /* Determine the distance from point 2 to either of the
                           * intersection points.
                           */
                          h = Math.sqrt((r0*r0) - (a*a));
                  
                          /* Now determine the offsets of the intersection points from
                           * point 2.
                           */
                          rx = -dy * (h/d);
                          ry = dx * (h/d);
                  
                          /* Determine the absolute intersection points. */
                          var xi = x2 + rx;
                          var xi_prime = x2 - rx;
                          var yi = y2 + ry;
                          var yi_prime = y2 - ry;
                  
                          return [xi, xi_prime, yi, yi_prime];
                      }
                  

                  这篇关于返回两个圆之间的 x,y 交点的 JavaScript 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:创建圆形 div 比使用图像更简单的方法? 下一篇:Three.js/WebGL:大球体在交叉路口出现破损

                  相关文章

                  最新文章

                  <tfoot id='ZuBto'></tfoot>

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

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

                    1. <legend id='ZuBto'><style id='ZuBto'><dir id='ZuBto'><q id='ZuBto'></q></dir></style></legend>