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

  • <tfoot id='uuDQi'></tfoot>
      <bdo id='uuDQi'></bdo><ul id='uuDQi'></ul>

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

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

        3D 中的射线和正方形/矩形相交

        时间:2023-09-12
        <i id='Xrd7U'><tr id='Xrd7U'><dt id='Xrd7U'><q id='Xrd7U'><span id='Xrd7U'><b id='Xrd7U'><form id='Xrd7U'><ins id='Xrd7U'></ins><ul id='Xrd7U'></ul><sub id='Xrd7U'></sub></form><legend id='Xrd7U'></legend><bdo id='Xrd7U'><pre id='Xrd7U'><center id='Xrd7U'></center></pre></bdo></b><th id='Xrd7U'></th></span></q></dt></tr></i><div id='Xrd7U'><tfoot id='Xrd7U'></tfoot><dl id='Xrd7U'><fieldset id='Xrd7U'></fieldset></dl></div>

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

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

      1. <tfoot id='Xrd7U'></tfoot>
          <bdo id='Xrd7U'></bdo><ul id='Xrd7U'></ul>

              <tbody id='Xrd7U'></tbody>

                • 本文介绍了3D 中的射线和正方形/矩形相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  嘿嘿.正在制作游戏,并且正在寻找仅在 3D 空间中与正方形或矩形相交的光线.在网上搜索并找到了许多解决方案,但我无法理解在 2D 中具有线段和线段相交脚本,但我无法弄清楚必须将其设为 3D.它从哪一侧与正方形或矩形相交并不重要,但它必须能够检索交点矢量,以便稍后可以测试它是否发生在同一光线交点上的其他交点之前或之后的距离.

                  Hei. Are making a game and are looking for a ray intersection onto a square or a rectangle only in 3D space. Have search the web and found many solutions but nothing i can understand have a line and line segment intersection script in 2D but i cant figure out have to make it 3D. It is not important from what side it intersect the square or rectangle but it must be able to retrive the point of intersection vector so that later can be tested for distance to se if it occurred before or after other intersections on the same ray intersection.

                  非常感谢任何 Python 或其他类似脚本语言的示例

                  Any examples in python or other similar scripting languages will be greatly appreciated

                  编辑:不知道必须修改 2D 以显示示例,但制作了新的并发布了两者.

                  Edit: Dont know have to modify the 2D to show an exaple but made a new and posting both.

                  //this is the exaple it test a ray onto a plane then look to se if that point is in the rectangle and saves it to test for distanse later
                  list Faces; //triangle faces
                  list Points; //
                  
                  vector FindPoint(){
                      //calcute the point of intersection onto the plane and returns it
                      //if it can intersect
                      //else return ZERO_VECTOR
                  }
                  
                  integer point-in-quadrilateral(){
                      //return 1 if the point is in the rectangular on the plane
                      //else return 0
                  }
                  
                  default{
                  
                      state_entry(){
                          integer n = (Faces != []); //return number of elements
                          integer x = 0;
                          while(x < n){
                              vector intersection = FindPoint( FromList(Faces, x) ); //take     out a element and runs it trough the function
                              if(intersection != ZERO_VECTOR){
                                  integer test = point-in-quadrilateral( FromList(Faces,     x) ); //find out if the point is in rectangular
                                  if(test == 1){ //if so
                                      Points += intersection; //save the point
                                  }
                              }
                              ++x;
                          }
                  
                          float first; //the distanse to the box intersection
                          integer l = (Points != []);
                          integer d;
                          while(d < l){
                              if(Dist( FromList(Points, d) ) < first) //if the new distanse     is less then first
                                  return 0; //then end script
                              ++d;
                          }
                      }
                  
                  }
                  
                  
                  //this is the 2D version
                  vector lineIntersection(vector one, vector two, vector three, vector four){
                  float bx = two.x - one.x;
                  float by = two.y - one.y;
                  float dx = four.x - three.x;
                  float dy = four.y - three.y; 
                  float b_dot_d_perp = bx*dy - by*dx;
                  if(b_dot_d_perp == 0.0) {
                      return ZERO_VECTOR;
                  }
                  float cx = three.x-one.x; 
                  float cy = three.y-one.y;
                  float t = (cx*dy - cy*dx) / b_dot_d_perp; 
                  if(LineSeg){ //if true tests for line segment
                      if((t < 0.0) || (t > 1.0)){
                          return ZERO_VECTOR;
                      }
                      float u = (cx * by - cy * bx) / b_dot_d_perp;
                      if((u < 0.0) || (u > 1.0)) {
                          return ZERO_VECTOR;
                      }
                  }
                  
                  return <one.x+t*bx, one.y+t*by, 0.0>; 
                  

                  }

                  推荐答案

                  为 R3 中的一条线创建一个矢量方程,然后求解该线在您测试它的矩形平面中的交点.之后,就可以很简单地测试该解点是否在边界内.

                  Create a vector equation for a line in R3, then solve for the intersection of that line in the plane of the rectangle that you are testing it against. After that, it's simple enough to test if that point of solution lies within the bounds.

                  解决方案的参数 t 可以通过以下方式找到:

                  the parameter t of the solution can be found with:

                  t = (a * (x0 - rx) + b * (y0 - ry) + c * (x0 - rz)) / (a * vx + b * vy + c * vz)
                  

                  在哪里:

                  a(x - x0) + b(y - y0) + c(z - z0) = 0
                  

                  是你的矩形所在平面的方程

                  is the equation of the plane that your rectangle lies on

                  和:

                  <x, y, z> = <rx + vx * t, ry + vy * t, rz + vz * t>
                  

                  是相关直线的矢量方程.

                  is the vector equation of the line in question.

                  注意:

                  <rx, ry, rz>
                  

                  是向量方程的初始点,并且

                  is the initial point of the vector equation, and

                  <vx, vy, vz>
                  

                  是上式的方向向量

                  之后,将参数 t 插入向量方程将为您提供测试距离的点.

                  After that, plugging the parameter t into your vector equation will give you the point to test for distance.

                  这篇关于3D 中的射线和正方形/矩形相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何检查一个点是否低于一条线? 下一篇:在点周围画椭圆

                  相关文章

                  最新文章

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

                      <tfoot id='qkdPi'></tfoot>

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