Beispiel #1
0
        /// <summary>
        /// This method calculates the distance of the array to a line only in case, if the distance is
        /// smaller than MaxDist., otherwise Utils.big will be returned.
        /// Imagine a cylinder with radius MaxDist around the polygon.
        /// If the line goes through the
        /// one of the cylinders,
        /// this line will be taken and the distance will be calculated and returned.
        /// </summary>
        /// <param name="L">The line, which will be tested</param>
        /// <param name="MaxDist">The maximal distance, for which a reasonable result can be returned.</param>
        /// <param name="param">A value for which the nearset point in the array can be evaluated with <see cref="Value"/></param>
        /// <param name="LineLam">A value for which the nearset point on the line can evaluated</param>
        /// <returns>In case the distance of the line is smaller than Maxdist, the distance is returned. Otherwise <see cref="Utils.big"/>
        /// </returns>
        public double Distance(LineType L, double MaxDist, out double param, out double LineLam)
        {
            double result = Utils.big;
            int    i;
            double di   = -1;
            double _lam = -1;
            double _mue = -1;

            param   = -1;
            LineLam = -1;
            xyz P1 = new xyz(0, 0, 0);
            xyz P2 = new xyz(0, 0, 0);

            for (i = 0; i < Count - 1; i++)
            {
                if (this[i + 1].dist(this[i]) < 0.00000001)
                {
                    continue;
                }
                LineType _L = new LineType(this[i], this[i + 1] - this[i]);

                di = _L.Distance(L, MaxDist, out _mue, out _lam);

                if (!Utils.Less(MaxDist, di) && (Utils.Less(di, result)) && (-0.001 < _mue) && (_mue < 1.0001))
                {
                    result  = di;
                    param   = i + _mue;
                    LineLam = _lam;
                }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the distance to a Point, if this distance is smaller than MaxDist. Otherwise <see cref="Utils.big"/> will be returned.
        /// </summary>
        /// <param name="Point">A Point</param>
        /// <param name="MaxDist">Maximal distance</param>
        /// <param name="LineLam">A value for which the nearest point in the array can evaluated with <see cref="Value"/></param>
        /// <returns>Distance.</returns>

        public double Distance(xyz Point, double MaxDist, out double LineLam)
        {
            double   result = Utils.big;
            xyz      Dummy;
            int      i;
            double   di, _lam;
            LineType L2;

            LineLam = -1;
            for (i = 1; i < Count; i++)
            {
                L2 = new LineType(this[i - 1], this[i].sub(this[i - 1]));

                di = L2.Distance(Point, out _lam, out Dummy);

                if (!Utils.Less(_lam, 0) && !Utils.Less(1, _lam))
                {
                    if (!Utils.Less(MaxDist, di) && (Utils.Less(di, result)))
                    {
                        result = di;

                        if (Utils.Equals(_lam, 1))
                        {
                            LineLam = i;
                        }
                        else
                        {
                            LineLam = i - 1 + _lam;
                        }
                    }
                }
                else
                {
                    double _di = Point.dist(this[i]);
                    if (!Utils.Less(MaxDist, _di) && (Utils.Less(_di, result)))
                    {
                        result  = _di;
                        LineLam = i;
                    }
                    if (i == 1)
                    {
                        _di = Point.dist(this[0]);
                        if (!Utils.Less(MaxDist, _di) && (Utils.Less(_di, result)))
                        {
                            result  = _di;
                            LineLam = 0;
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Checks intersecting of a not bounded Line with the Triangle
        /// </summary>
        /// <param name="L">Not bounded Line</param>
        /// <returns></returns>
        public bool Intersect(LineType L)
        {
            double Lam = -1;

            xyz   Pkt = new Drawing3d.xyz(0, 0, 0);
            Plane P   = new Plane(A, B, C);

            P.Cross(L, out Lam, out Pkt);
            xyz Dummy = new xyz(0, 0, 0);

            xyz      SA = A.sub(Pkt);
            xyz      SB = B.sub(Pkt);
            xyz      SC = C.sub(Pkt);
            LineType LL = new LineType(A, (B - A).normalized());
            double   bb = LL.Distance(Pkt, out Lam, out Dummy);

            if (bb < 0.1)
            {
            }
            LL = new LineType(B, (C - B).normalized());
            bb = LL.Distance(Pkt, out Lam, out Dummy);
            if (bb < 0.1)
            {
            }
            LL = new LineType(C, (C - A).normalized());
            bb = LL.Distance(Pkt, out Lam, out Dummy);
            if (bb < 0.1)
            {
            }
            //double D1 = Utils.Spat(SA, SB, L.Direction);
            //double D2 = Utils.Spat(SB, SC, L.Direction);
            //double D3 = Utils.Spat(SC, SA, L.Direction);
            double D1 = Utils.Spat(SA, SB, SC);

            return(true);
            //if (Utils.Less(0, D1))
            //{
            //    return (Utils.Less(0, D2) && Utils.Less(0, D3));
            //}
            //else
            //    return (Utils.Less(D2, 0)) && (Utils.Less(D3, 0));
        }