------------------------------------------------------------------------------ Method intersects two polygons. You must supply the number of points and point coordinates (npts, *pts) and the bounding box (bounds) of the two polygons. Also supply a tolerance squared for controlling error. The method returns 1 if there is an intersection, and 0 if not. A single point of intersection x[3] is also ret
| 2088 | // not. A single point of intersection x[3] is also returned if there |
| 2089 | // is an intersection. |
| 2090 | int vtkPolygon::IntersectPolygonWithPolygon(int npts, double* pts, double bounds[6], int npts2, |
| 2091 | double* pts2, double bounds2[6], double tol2, double x[3]) |
| 2092 | { |
| 2093 | double n[3], coords[3]; |
| 2094 | int i, j; |
| 2095 | double *p1, *p2, ray[3]; |
| 2096 | double t; |
| 2097 | |
| 2098 | // Intersect each edge of first polygon against second |
| 2099 | // |
| 2100 | vtkPolygon::ComputeNormal(npts2, pts2, n); |
| 2101 | |
| 2102 | for (i = 0; i < npts; i++) |
| 2103 | { |
| 2104 | p1 = pts + 3 * i; |
| 2105 | p2 = pts + 3 * ((i + 1) % npts); |
| 2106 | |
| 2107 | for (j = 0; j < 3; j++) |
| 2108 | { |
| 2109 | ray[j] = p2[j] - p1[j]; |
| 2110 | } |
| 2111 | if (!vtkBox::IntersectBox(bounds2, p1, ray, coords, t)) |
| 2112 | { |
| 2113 | continue; |
| 2114 | } |
| 2115 | |
| 2116 | if ((vtkPlane::IntersectWithLine(p1, p2, n, pts2, t, x)) == 1) |
| 2117 | { |
| 2118 | if ((npts2 == 3 && vtkTriangle::PointInTriangle(x, pts2, pts2 + 3, pts2 + 6, tol2)) || |
| 2119 | (npts2 > 3 && vtkPolygon::PointInPolygon(x, npts2, pts2, bounds2, n) == VTK_POLYGON_INSIDE)) |
| 2120 | { |
| 2121 | return 1; |
| 2122 | } |
| 2123 | } |
| 2124 | else |
| 2125 | { |
| 2126 | return 0; |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | // Intersect each edge of second polygon against first |
| 2131 | // |
| 2132 | vtkPolygon::ComputeNormal(npts, pts, n); |
| 2133 | |
| 2134 | for (i = 0; i < npts2; i++) |
| 2135 | { |
| 2136 | p1 = pts2 + 3 * i; |
| 2137 | p2 = pts2 + 3 * ((i + 1) % npts2); |
| 2138 | |
| 2139 | for (j = 0; j < 3; j++) |
| 2140 | { |
| 2141 | ray[j] = p2[j] - p1[j]; |
| 2142 | } |
| 2143 | |
| 2144 | if (!vtkBox::IntersectBox(bounds, p1, ray, coords, t)) |
| 2145 | { |
| 2146 | continue; |
| 2147 | } |
nothing calls this directly
no test coverage detected