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

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

    1. <legend id='rTSU5'><style id='rTSU5'><dir id='rTSU5'><q id='rTSU5'></q></dir></style></legend>
        <bdo id='rTSU5'></bdo><ul id='rTSU5'></ul>

        给定起点和终点以及距离,计算沿线的点

        时间:2023-09-15
        <legend id='F02Vo'><style id='F02Vo'><dir id='F02Vo'><q id='F02Vo'></q></dir></style></legend>
        1. <tfoot id='F02Vo'></tfoot>
            • <bdo id='F02Vo'></bdo><ul id='F02Vo'></ul>

              1. <small id='F02Vo'></small><noframes id='F02Vo'>

                  <tbody id='F02Vo'></tbody>
                • <i id='F02Vo'><tr id='F02Vo'><dt id='F02Vo'><q id='F02Vo'><span id='F02Vo'><b id='F02Vo'><form id='F02Vo'><ins id='F02Vo'></ins><ul id='F02Vo'></ul><sub id='F02Vo'></sub></form><legend id='F02Vo'></legend><bdo id='F02Vo'><pre id='F02Vo'><center id='F02Vo'></center></pre></bdo></b><th id='F02Vo'></th></span></q></dt></tr></i><div id='F02Vo'><tfoot id='F02Vo'></tfoot><dl id='F02Vo'><fieldset id='F02Vo'></fieldset></dl></div>
                  本文介绍了给定起点和终点以及距离,计算沿线的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  寻找计算直线上点的最快方法离线的终点给定的距离:

                  Looking for the quickest way to calculate a point that lies on a line a given distance away from the end point of the line:

                  void calculate_line_point(int x1, int y1, int x2, int y2, int distance, int *px, int *py) 
                  {
                      //calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2
                      *px = ???
                      *py = ???
                  }  
                  

                  感谢您的回复,不,这不是作业,只是一些黑客攻击我通常的专业领域.

                  Thanks for the responses, no this is not homework, just some hacking out of my normal area of expertise.

                  这是下面建议的功能.它不接近工作.如果我在右上角的 90 度部分每 5 度计算一个点一个圆作为起点并调用下面的函数,圆心为x2,y2,距离为4,终点完全错误.它们位于中心的下方和右侧,长度与中心点一样长.有人有什么建议吗?

                  This is the function suggested below. It's not close to working. If I calculate points every 5 degrees on the upper right 90 degree portion of a circle as starting points and call the function below with the center of the circle as x2,y2 with a distance of 4 the end points are totally wrong. They lie below and to the right of the center and the length is as long as the center point. Anyone have any suggestions?

                  void calculate_line_point(int x1, int y1, int x2, int y2, int distance)
                  {
                  
                  //calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2
                  
                    double vx = x2 - x1; // x vector
                    double vy = y2 - y1; // y vector
                  
                    double mag = sqrt(vx*vx + vy*vy); // length
                  
                    vx /= mag;
                    vy /= mag;
                  
                  // calculate the new vector, which is x2y2 + vxvy * (mag + distance).
                  
                    px = (int) ( (double) x2 + vx * (mag + (double)distance) );
                    py = (int) ( (double) y2 + vy * (mag + (double)distance) );
                  

                  }

                  我在stackoverflow但不完全理解,谁能解释一下?

                  I've found this solution on stackoverflow but don't understand it completely, can anyone clarify?

                  推荐答案

                  我认为这属于 MathOverflow,但我会回答,因为这是您的第一篇文章.首先计算从 x1y1 到 x2y2 的向量:

                  I think this belongs on MathOverflow, but I'll answer since this is your first post. First you calculate the vector from x1y1 to x2y2:

                  float vx = x2 - x1;
                  float vy = y2 - y1;
                  

                  然后计算长度:

                  float mag = sqrt(vx*vx + vy*vy);
                  

                  将向量归一化为单位长度:

                  Normalize the vector to unit length:

                  vx /= mag;
                  vy /= mag;
                  

                  最后计算出新的向量,即x2y2 + vxvy * (mag + distance).

                  Finally calculate the new vector, which is x2y2 + vxvy * (mag + distance).

                  *px = (int)((float)x1 + vx * (mag + distance));
                  *py = (int)((float)y1 + vy * (mag + distance));
                  

                  您可以省略一些乘以距离/mag 的计算.

                  You can omit some of the calculations multiplying with distance / mag instead.

                  这篇关于给定起点和终点以及距离,计算沿线的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:std::lower_bound 对于 std::vector 比 std::map::find 慢 下一篇:在 std::vector 上的 Openmp 和减少?

                  相关文章

                  最新文章

                  1. <small id='j5X4w'></small><noframes id='j5X4w'>

                  2. <tfoot id='j5X4w'></tfoot>

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

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