How to know if a line intersects a plane in C#?

后端 未结 7 1438
情话喂你
情话喂你 2020-12-13 18:39

I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle.

7条回答
  •  Happy的楠姐
    2020-12-13 18:41

    If it is 2d, then all lines are on the only plane.

    So, this is basic 3-D geometry. You should be able to do this with a straightforward equation.

    Check out this page:

    http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/.

    The second solution should be easy to implement, as long as you translate the coordinates of your rectangle into the equation of a plane.

    Furthermore, check that your denominator isn't zero (line doesn't intersect or is contained in the plane).

提交回复
热议问题