Intersect a line segment with a plane Return values: 'p': The segment lies wholly within the plane. 'q': The(first) q endpoint is on the plane (but not 'p'). 'r' : The(second) r endpoint is on the plane (but not 'p'). '0' : The segment lies strictly to one side or the other of the plane. '1': The segment intersects the plane, and none of {p, q, r} hold.
| 156 | // '0' : The segment lies strictly to one side or the other of the plane. |
| 157 | // '1': The segment intersects the plane, and none of {p, q, r} hold. |
| 158 | char compute_segment_plane_intersection(vec3& p, const vec3& normal, const double& d_coeff, |
| 159 | const vec3& q, const vec3& r) |
| 160 | { |
| 161 | |
| 162 | // vec3 planeNormal; |
| 163 | // double planeDCoeff; |
| 164 | // planeNormalLargestComponent = compute_polygon_plane_coefficients(planeNormal, planeDCoeff, polygonVertices, |
| 165 | // polygonVertexCount); |
| 166 | |
| 167 | double num = d_coeff - dot_product(q, normal); |
| 168 | const vec3 rq = (r - q); |
| 169 | double denom = dot_product(rq, normal); |
| 170 | |
| 171 | if (denom == double(0.0) /* Segment is parallel to plane.*/) { |
| 172 | if (num == double(0.0)) { // 'q' is on plane. |
| 173 | return 'p'; // The segment lies wholly within the plane |
| 174 | } else { |
| 175 | return '0'; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | double t = num / denom; |
| 180 | |
| 181 | for (int i = 0; i < 3; ++i) { |
| 182 | p[i] = q[i] + t * (r[i] - q[i]); |
| 183 | } |
| 184 | |
| 185 | if ((double(0.0) < t) && (t < double(1.0))) { |
| 186 | return '1'; // The segment intersects the plane, and none of {p, q, r} hold |
| 187 | } else if (num == double(0.0)) // t==0 |
| 188 | { |
| 189 | return 'q'; // The (first) q endpoint is on the plane (but not 'p'). |
| 190 | } else if (num == denom) // t==1 |
| 191 | { |
| 192 | return 'r'; // The (second) r endpoint is on the plane (but not 'p'). |
| 193 | } else { |
| 194 | return '0'; // The segment lies strictly to one side or the other of the plane |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | bool determine_three_noncollinear_vertices(int& i, int& j, int& k, const std::vector<vec3>& polygon_vertices, |
| 199 |
no test coverage detected