-1

Ray and segment of polygon lie in the same plane. The normal vector of this plane is known. I need to know if a ray intersects this segment

  • 1
    Hi CPPser, could you provide some more information? A segment is defined as a section of a line? or a part of a plane? make the relations clear. In this case, an image as sketch might be useful – schetefan24 Nov 14 '20 at 13:02
  • Hi, It is segment of polygon) –  Nov 14 '20 at 13:04
  • How is your polygon stored? Do you have a container (vector, list, etc) containing the edges or corners? – schetefan24 Nov 14 '20 at 13:08
  • a possible way to solve it would be searching the intersections between edges of the polygon and the ray. If it intersects any edge, you have a hit (assuming that they are in the same plane, otherwise it doesn't work that easy) – schetefan24 Nov 14 '20 at 13:09
  • 2
    Intersection of segments in 3d is somehow unreliable. Due to rounding issues, they may not intersect even if they should mathematically. A more reliable approach is to determine the points with closest distance. (If these segments are in a plane the distance between these points should be very small - just the amount caused by rounding issues.) Another approach could be to project the segments into 2d using the plane normal as projection vector. Then you can do a (much more reliable) 2d intersection. – Scheff's Cat Nov 14 '20 at 13:52
  • exactly you need to account for the rounding errors... see [Cone to box collision](https://stackoverflow.com/a/62257945/2521214) and look for `line closest(line l0,axis a0);` it will return the 2 closest points between line and ray in 3D so simply compute the distance between them and if less than threshold you found your intersection) – Spektre Nov 15 '20 at 13:26

1 Answers1

2

Choose the largest component of plane normal and make projection onto corresponding plane OXY, OXZ or OYZ (in general we can use any non-zero component)

Say Z-component is the largest, so make projection onto OXY plane. This projection is very simple - just use X and Y components. You have rather simple 2d problem now. (Example for line segments intersection).

MBo
  • 77,366
  • 5
  • 53
  • 86