1

I have an array of triangle vertices (faces of the polygon), something like

[[[a, b, c], [d, e, f], [g, h, i]], ...]

I have a line segment, represented by 2 3D vertices, let's say [[j, k, l], [m, n, o]].

And I have a point [p, q, r].

What I want to do is, project the point on the polygon, through the line segment, and check if it completely slices the polygon (I think 4 points of contact should be enough? I could be wrong). And if it does, I need all the points of intersection which lie on the edges and vertices.

I'm completely lost here. Any pointers would be appreciated.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • Polygons are 2D. Polyhedra require a plane in order to be cut. – Ignacio Vazquez-Abrams Jul 22 '12 at 06:04
  • @IgnacioVazquez-Abrams Didn't know it was called a polyhedron. Thanks! What do you mean by "require a plane"? – Dogbert Jul 22 '12 at 06:10
  • A line cannot slice a polyhedron; it doesn't have enough dimensions. – Ignacio Vazquez-Abrams Jul 22 '12 at 06:11
  • Yeah, correct me if I'm wrong, but wouldn't a point and a line segment be enough? The plane would could be considered a ray from the point to every point of the line segment. Wouldn't that construct an infinite plane? And be enough for slicing? – Dogbert Jul 22 '12 at 06:13
  • Okay, I see what the question is asking now. But there will be an infinite number of points of intersection; perhaps you should restrict the requirement to points of intersection at edges and vertices. – Ignacio Vazquez-Abrams Jul 22 '12 at 06:17
  • Ah yes, my mistake. I want the points of intersection at edges and vertices. Corrected the question. – Dogbert Jul 22 '12 at 06:18
  • Why would 4 points of contact be enough? Since the triangle formed from your point+line segment defines only part of a plane, then it's very possible that there would be 4 POI or more, but the triangle doesn't "completely slice the polygon", but rather cuts part of it. – davin Jul 22 '12 at 07:11

1 Answers1

1

We can assume without loss of generality that the triangle formed by the point & line segment (henceforth T) lies in the x-y plane. (Otherwise, rotate everything appropriately).

We loop through the triangle faces, for any pair of vertices of a face where their y-coordinates have different signs (i.e. for any edge that cuts the x-y plane), we check the intersection of the edge with the x-y plane and make sure it's within T.

It holds that T "completely slices the polygon" if and only if all such checks are true.

Running time is O(number of faces).

All the operations described are pretty simple. E.g. Checking that something is in the bounds of T is simply checking two inequalities with the equations of the two lines that define T (i.e. from the point to the end points of the line segment).

All POI with the edges (and thus vertices) can be calculated within the loop - it's simply the POI of the edge with the x-y plane.

davin
  • 44,863
  • 9
  • 78
  • 78