コード例 #1
0
        private bool CutLineHull3D([NotNull] Pnt3D p0s,
                                   [NotNull] Pnt3D l0,
                                   [NotNull] Pnt3D p1s,
                                   [NotNull] Pnt3D l1,
                                   double r2,
                                   out double tMin, out double tMax,
                                   out NearSegment hullStartNear,
                                   out NearSegment hullEndNear)
        {
            // Equation for points X on cylinder around p1 + u * l1 with square radius = r2
            //                2          2
            // ((X - p1) x l1)  = r2 * l1
            //
            // with X = p0 + t * l0, tMin and tMax can be determined
            //
            hullStartNear = NearSegment.NotNear;
            hullEndNear   = NearSegment.NotNear;

            if (Geom.IsParallel)             // parallel
            {
                return(Parallel(p0s, l0, p1s, l1, r2,
                                out tMin, out tMax, ref hullStartNear,
                                ref hullEndNear));
            }

            double l12   = l1 * l1;
            double r2l12 = r2 * l12;

            var   p0_p1    = (Pnt3D)(p0s - p1s);
            Pnt3D p0_p1xl1 = p0_p1.VectorProduct(l1);

            if (SegmentUtils.SolveSqr(Geom.L0xl12, 2 * Geom.L0xl1 * p0_p1xl1,
                                      p0_p1xl1 * p0_p1xl1 - r2l12,
                                      out tMin, out tMax))
            {
                return(Near(p0s, l0, p1s, l1, r2, l12, ref tMin, ref tMax,
                            ref hullStartNear, ref hullEndNear));
            }

            return(false);
        }
コード例 #2
0
        private bool CutLineHull2D([NotNull] Pnt p0,
                                   [NotNull] Pnt l0,
                                   [NotNull] Pnt p1,
                                   [NotNull] Pnt l1,
                                   double r2,
                                   out double tMin, out double tMax,
                                   out NearSegment hullStartNear,
                                   out NearSegment hullEndNear)
        {
            // Equation for points X on cylinder around p1 + u * l1 with square radius = r2
            //                2          2
            // ((X - p1) x l1)  = r2 * l1
            //
            // with X = p0 + t * l0, tMin and tMax can be determined
            //
            hullStartNear = NearSegment.NotNear;
            hullEndNear   = NearSegment.NotNear;

            if (Geom.IsParallel)             // parallel
            {
                return(Parallel(p0, l0, p1, l1, r2, out tMin, out tMax, ref hullStartNear,
                                ref hullEndNear));
            }

            double r2l12 = r2 * L12;

            double t0 = (p0.X - p1.X) * l1.Y - (p0.Y - p1.Y) * l1.X;

            if (SegmentUtils.SolveSqr(T1 * T1, 2 * T1 * t0, t0 * t0 - r2l12, out tMin, out tMax))
            {
                return(Near(p0, l0, p1, l1, r2, L12, ref tMin, ref tMax,
                            ref hullStartNear, ref hullEndNear));
            }

            return(false);
        }