| 16 | using namespace LNLib; |
| 17 | |
| 18 | CurveCurveIntersectionType Intersection::ComputeRays( |
| 19 | const XYZ& point0, const XYZ& vector0, |
| 20 | const XYZ& point1, const XYZ& vector1, |
| 21 | double& param0, double& param1, XYZ& intersectPoint) |
| 22 | { |
| 23 | if (vector0.IsAlmostEqualTo(vector1)) |
| 24 | { |
| 25 | if (point0.IsAlmostEqualTo(point1)) |
| 26 | { |
| 27 | intersectPoint = point0; |
| 28 | param0 = param1 = 0; |
| 29 | return CurveCurveIntersectionType::Intersecting; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | VALIDATE_ARGUMENT(!vector0.IsZero(), "vector0", "Vector0 must not be zero."); |
| 34 | VALIDATE_ARGUMENT(!vector1.IsZero(), "vector1", "Vector1 must not be zero."); |
| 35 | |
| 36 | XYZ diff = point0 - point1; |
| 37 | |
| 38 | double a = vector0.DotProduct(vector0); |
| 39 | double b = vector0.DotProduct(vector1); |
| 40 | double c = vector1.DotProduct(vector1); |
| 41 | double d = vector0.DotProduct(diff); |
| 42 | double e = vector1.DotProduct(diff); |
| 43 | |
| 44 | double denom = a * c - b * b; |
| 45 | |
| 46 | if (MathUtils::IsAlmostEqualTo(std::abs(denom), 0.0)) { |
| 47 | XYZ w = point1 - point0; |
| 48 | if (MathUtils::IsAlmostEqualTo(w.CrossProduct(vector0).Length(), 0.0)) { |
| 49 | param0 = param1 = 0.0; |
| 50 | intersectPoint = point0; |
| 51 | return CurveCurveIntersectionType::Coincident; |
| 52 | } |
| 53 | else { |
| 54 | return CurveCurveIntersectionType::Parallel; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | param0 = (b * e - c * d) / denom; |
| 59 | param1 = (a * e - b * d) / denom; |
| 60 | |
| 61 | XYZ p0 = point0 + vector0 * param0; |
| 62 | XYZ p1 = point1 + vector1 * param1; |
| 63 | |
| 64 | if (MathUtils::IsAlmostEqualTo(p0.Distance(p1),0.0)) { |
| 65 | intersectPoint = (p0 + p1) * 0.5; |
| 66 | return CurveCurveIntersectionType::Intersecting; |
| 67 | } |
| 68 | else { |
| 69 | intersectPoint = p0; |
| 70 | return CurveCurveIntersectionType::Skew; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | LinePlaneIntersectionType LNLib::Intersection::ComputeLineAndPlane( |
| 75 | const XYZ& normal, |
nothing calls this directly
no test coverage detected