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

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

  3. <legend id='jvXww'><style id='jvXww'><dir id='jvXww'><q id='jvXww'></q></dir></style></legend>
      <tfoot id='jvXww'></tfoot>

      查找坐标以在线的末端绘制箭头(等腰三角形)

      时间:2023-09-08
      1. <tfoot id='khPka'></tfoot>
          <tbody id='khPka'></tbody>
        <legend id='khPka'><style id='khPka'><dir id='khPka'><q id='khPka'></q></dir></style></legend>

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

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

                本文介绍了查找坐标以在线的末端绘制箭头(等腰三角形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试创建一个函数,该函数将返回我想在行尾绘制的箭头(等腰三角形)的 3 点坐标.

                I am trying to create a function that will return the 3 points coordinates of arrow head (isoscele triangle) that I want to draw at the end of a line.

                挑战在于线的方向(角度)可以在象限中的 0 到 360 度之间变化.

                The challenge is in the orientation (angle) of the line that can vary between 0 and 360 degree in the quadrant.

                我有以下价值观:

                //start coordinates of the line
                var x0 = 100;
                var y0 = 100;
                
                //end coordinates of the line
                var x1 = 200;
                var y1 = 200;
                
                //height of the triangle
                var h = 10;
                //width of the base of the triangle
                var w = 30 ;
                

                到目前为止,这是我的函数,它返回三角形底边的两点坐标:

                This is my function until now that returns the two point coordinates of the base of the triangle:

                var drawHead = function(x0, y0, x1, y1, h, w){
                    var L = Math.sqrt(Math.pow((x0 - x1),2)+Math.pow((y0 - y1),2));
                
                    //first base point coordinates
                    var base_x0 = x1 + (w/2) * (y1 - y0) / L;
                    var base_y0 = y1 + (w/2) * (x0 - x1) / L;
                
                    //second base point coordinates
                    var base_x1 = x1 - (w/2) * (y1 - y0) / L;
                    var base_y1 = y1 - (w/2) * (x0 - x1) / L;
                
                    //now I have to find the last point coordinates ie the top of the arrow head
                }
                

                如何根据线的角度确定三角形顶部的坐标?

                How can I determine the coordinates of the top of the triangle considering the angle of the line?

                推荐答案

                箭头的头部与箭头的主体在同一条线上.因此,(x1, y1) 和 (head_x, head_y) 之间的线段的斜率将与 (x0, y0) 和 (x1, y1) 之间的线段的斜率相同.假设 dx = head_x - x1 和 dy = head_y - y1 和斜率 = (y1 - y0)/(x1 - x0).因此,dy/dx = 斜率.我们也知道 dx^2 + dy^2 = h^2.我们可以根据斜率和 h 求解 dx.那么,dy = dx * 斜率.一旦你有了 dx 和 dy,你就可以将它们添加到 x1 和 y1 来获得头点.一些伪代码:

                The head of the arrow will lie along the same line as the body of the arrow. Therefore, the slope of the line segment between (x1, y1) and (head_x, head_y) will be the same as the slope of the line segment between(x0, y0) and (x1, y1). Let's say that dx = head_x - x1 and dy = head_y - y1 and slope = (y1 - y0) / (x1 - x0). Therefore, dy / dx = slope. We also know that dx^2 + dy^2 = h^2. We can solve for dx in terms of slope and h. Then, dy = dx * slope. Once you have dx and dy, you can just add those to x1 and y1 to get the head point. Some pseudocode:

                if x1 == x0: #avoid division by 0
                    dx = 0
                    dy = h
                    if y1 < y0:
                        dy = -h #make sure arrow head points the right way
                    else:
                        dy = h
                else:
                    if x1 < x0: #make sure arrow head points the right way
                        h = -h
                    slope = (y1 - y0) / (x1 - x0)
                    dx = h / sqrt(1 + slope^2)
                    dy = dx * slope
                head_x = x1 + dx
                head_y = y1 + dy
                

                这篇关于查找坐标以在线的末端绘制箭头(等腰三角形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何用 CSS 绘制一个不完整的圆圈以及如何在其中 下一篇:如何定位相机以使对象在屏幕上始终具有相同的

                相关文章

                最新文章

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

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

                  <tfoot id='alEN7'></tfoot>