diff Framework/Toolbox/CoordinateSystem3D.cpp @ 151:c5044bbfc303 wasm

CoordinateSystem3D::IntersectSegment()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Feb 2018 17:37:03 +0100
parents e2fe9352f240
children 2e023be0563c
line wrap: on
line diff
--- a/Framework/Toolbox/CoordinateSystem3D.cpp	Thu Feb 01 16:07:54 2018 +0100
+++ b/Framework/Toolbox/CoordinateSystem3D.cpp	Thu Feb 01 17:37:03 2018 +0100
@@ -168,4 +168,24 @@
     offsetX = boost::numeric::ublas::inner_prod(axisX_, projection - origin_);
     offsetY = boost::numeric::ublas::inner_prod(axisY_, projection - origin_);
   }
+
+
+  bool CoordinateSystem3D::IntersectSegment(double& x,
+                                            double& y,
+                                            const Vector& edgeFrom,
+                                            const Vector& edgeTo) const
+  {
+    Vector p;
+    double d = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]);
+    if (GeometryToolbox::IntersectPlaneAndSegment(p, normal_, d, edgeFrom, edgeTo))
+    {
+      ProjectPoint(x, y, p);  // TODO could be optimized, as the point
+                              // is on the plane by construction
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
 }