Example #1
0
        /// <summary>
        /// { Returns the triangle neighbouring aTriangle which is nearer to
        /// aPoint than aTriangle.If aPoint is in aTriangle then aTriangle is
        /// returned, and found set to true. If aPoint is outside the model,
        /// returns Nil - requires model to be convex. }
        /// </summary>
        /// <param name="aPoint"></param>
        /// <param name="aTriangle"></param>
        /// <param name="lastTri"></param>
        /// <param name="found"></param>
        /// <returns></returns>
        protected Triangle GetBestTri(TriVertex aPoint, Triangle aTriangle, Triangle lastTri, out bool found)
        {
            Triangle Result;

            found = false;

            TriVertex firstPoint  = aTriangle.Vertices[0];
            TriVertex secondPoint = aTriangle.Vertices[1];

            if (aTriangle.Neighbours[0] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, firstPoint, secondPoint))
            {
                Result = aTriangle.Neighbours[0];
            }
            else
            {
                TriVertex thirdPoint = aTriangle.Vertices[2];
                if (aTriangle.Neighbours[1] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, secondPoint, thirdPoint))
                {
                    Result = aTriangle.Neighbours[1];
                }
                else if (aTriangle.Neighbours[2] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, thirdPoint, firstPoint))
                {
                    Result = aTriangle.Neighbours[2];
                }
                else // to the right of each line -must be inside aTriangle
                {
                    Result = aTriangle;
                    found  = true;
                }
            }

            return(Result);
        }
Example #2
0
        /// <summary>
        /// Returns true if the circumcircle of theTri contains theCoordRec
        /// </summary>
        /// <param name="theTri"></param>
        /// <param name="theCoord"></param>
        /// <returns></returns>
        protected bool Influenced(Triangle theTri, TriVertex theCoord)
        {
            var result = false;

            double cotan = TinningUtils.Cotangent(theTri.Vertices[2], theTri.Vertices[0], theTri.Vertices[1]);

            if (cotan > -1E20)
            {
                double cNorth = ((theTri.Vertices[1].Y + theTri.Vertices[0].Y) / 2) -
                                ((theTri.Vertices[1].X - theTri.Vertices[0].X) / 2) *
                                cotan;
                double cEast = ((theTri.Vertices[1].X + theTri.Vertices[0].X) / 2) +
                               ((theTri.Vertices[1].Y - theTri.Vertices[0].Y) / 2) *
                               cotan;
                double radSq = Math.Pow(cNorth - theTri.Vertices[0].Y, 2) + Math.Pow(cEast - theTri.Vertices[0].X, 2);

                result = Math.Pow(theCoord.X - cEast, 2) + Math.Pow(theCoord.Y - cNorth, 2) < radSq;
            }

            return(result);
        }