------------------------------------------------------------------------------ Plane intersection plus in/out test on triangle. The in/out test is performed using tol as the tolerance.
| 545 | // Plane intersection plus in/out test on triangle. The in/out test is |
| 546 | // performed using tol as the tolerance. |
| 547 | int vtkTriangle::IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, |
| 548 | double x[3], double pcoords[3], int& subId) |
| 549 | { |
| 550 | double closestPoint[3]; |
| 551 | double dist2 = 0.0; |
| 552 | double tol2 = tol * tol; |
| 553 | double weights[3]; |
| 554 | |
| 555 | subId = 0; |
| 556 | pcoords[2] = 0.0; |
| 557 | |
| 558 | // Get normal for triangle |
| 559 | // |
| 560 | double pt1[3]; |
| 561 | double pt2[3]; |
| 562 | double pt3[3]; |
| 563 | vtkPoints* points = this->Points; |
| 564 | points->GetPoint(1, pt1); |
| 565 | points->GetPoint(2, pt2); |
| 566 | points->GetPoint(0, pt3); |
| 567 | |
| 568 | double n[3]; |
| 569 | vtkTriangle::ComputeNormal(pt1, pt2, pt3, n); |
| 570 | |
| 571 | if (n[0] != 0.0 || n[1] != 0.0 || n[2] != 0.0) |
| 572 | { |
| 573 | // Intersect plane of triangle with line |
| 574 | // |
| 575 | if (!vtkPlane::IntersectWithLine(p1, p2, n, pt1, t, x)) |
| 576 | { |
| 577 | // If the line and the triangle are not parallel or not coplanar |
| 578 | if (t != VTK_DOUBLE_MAX || (vtkMath::Dot(n, pt1) - vtkMath::Dot(n, p1)) != 0.0) |
| 579 | { |
| 580 | pcoords[0] = pcoords[1] = 0.0; |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | // When the line is coplanar with the triangle, the intersection point is chosen to be the |
| 585 | // closest to p1. |
| 586 | |
| 587 | // If p1 is inside the triangle |
| 588 | if (this->EvaluatePosition(p1, closestPoint, subId, pcoords, dist2, weights) == 1) |
| 589 | { |
| 590 | t = 0.0; |
| 591 | x[0] = p1[0]; |
| 592 | x[1] = p1[1]; |
| 593 | x[2] = p1[2]; |
| 594 | return 1; |
| 595 | } |
| 596 | |
| 597 | // If p1 is outside of the triangle |
| 598 | bool intersection = false; |
| 599 | double closestDistance = VTK_DOUBLE_MAX; |
| 600 | double closestX[3] = { 0., 0., 0. }; |
| 601 | double closestPCoords[3] = { 0., 0., 0. }; |
| 602 | |
| 603 | for (vtkIdType i = 0; i < this->GetNumberOfEdges(); i++) |
| 604 | { |
nothing calls this directly
no test coverage detected