MCPcopy Create free account
hub / github.com/Kitware/VTK / IntersectWithLine

Method IntersectWithLine

Common/DataModel/vtkPlane.cxx:271–330  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Given a line defined by the two points p1,p2; and a plane defined by the normal n and point p0, compute an intersection. The parametric coordinate along the line is returned in t, and the coordinates of intersection are returned in x. A zero is returned if the plane and line do not intersect between (0<=t<=1). If the pl

Source from the content-addressed store, hash-verified

269// do not intersect between (0<=t<=1). If the plane and line are parallel,
270// zero is returned and t is set to VTK_LARGE_DOUBLE.
271int vtkPlane::IntersectWithLine(
272 const double p1[3], const double p2[3], double n[3], double p0[3], double& t, double x[3])
273{
274 double num, den, p21[3];
275 double fabsden, fabstolerance;
276
277 // Compute line vector
278 //
279 p21[0] = p2[0] - p1[0];
280 p21[1] = p2[1] - p1[1];
281 p21[2] = p2[2] - p1[2];
282
283 // Compute denominator. If ~0, line and plane are parallel.
284 //
285 num = vtkMath::Dot(n, p0) - (n[0] * p1[0] + n[1] * p1[1] + n[2] * p1[2]);
286 den = n[0] * p21[0] + n[1] * p21[1] + n[2] * p21[2];
287 //
288 // If denominator with respect to numerator is "zero", then the line and
289 // plane are considered parallel.
290 //
291
292 // trying to avoid an expensive call to fabs()
293 if (den < 0.0)
294 {
295 fabsden = -den;
296 }
297 else
298 {
299 fabsden = den;
300 }
301 if (num < 0.0)
302 {
303 fabstolerance = -num * VTK_PLANE_TOL;
304 }
305 else
306 {
307 fabstolerance = num * VTK_PLANE_TOL;
308 }
309 if (fabsden <= fabstolerance)
310 {
311 t = VTK_DOUBLE_MAX;
312 return 0;
313 }
314
315 // valid intersection
316 t = num / den;
317
318 x[0] = p1[0] + t * p21[0];
319 x[1] = p1[1] + t * p21[1];
320 x[2] = p1[2] + t * p21[2];
321
322 if (t >= 0.0 && t <= 1.0)
323 {
324 return 1;
325 }
326 else
327 {
328 return 0;

Callers

nothing calls this directly

Calls 3

DotFunction · 0.70
GetNormalMethod · 0.45
GetOriginMethod · 0.45

Tested by

no test coverage detected