Ejemplo n.º 1
0
            //sub
            private Line SetEachMainAxis(Vector3d guide, Polyline bound)
            {
                Line axis1 = PCXTools.PCXLongest(Pt, bound, guide);
                Line axis2 = PCXTools.PCXLongest(Pt, bound, -guide);

                bool isAxis1Longer = axis1.Length >= axis2.Length;
                bool isAxis1Inside = IsLineInside(axis1, bound);
                bool isAxis2Inside = IsLineInside(axis2, bound);

                if (isAxis1Inside)
                {
                    if (!isAxis2Inside)
                    {
                        return(axis1);
                    }

                    if (isAxis1Longer)
                    {
                        return(axis1);
                    }

                    return(axis2);
                }

                if (isAxis2Inside)
                {
                    return(axis2);
                }

                return(new Line(Pt, Pt));
            }
Ejemplo n.º 2
0
            //point adding
            private void AddMidPtWhenTriangle()
            {
                if (itSegments.Count != 3)
                {
                    return;
                }

                List <InitialPt> triangleInit = new List <InitialPt>();

                for (int i = 0; i < itSegments.Count; i++)
                {
                    Vector3d perpFromSegment = itSegments[i].Line.UnitTangent;
                    perpFromSegment.Rotate(Math.PI / 2, Vector3d.ZAxis);

                    for (int j = 0; j < itSegments.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }

                        Line    pcxLine    = PCXTools.PCXStrict(itSegments[j].Line.PointAt(0.5), boundary, -perpFromSegment);
                        Point3d pointToSeg = pcxLine.To;

                        if (pcxLine.Length == 0 || !PCXTools.IsPtOnLine(pointToSeg, itSegments[i].Line, 0.5))
                        {
                            continue;
                        }

                        Vector3d perpVec = pcxLine.From - pcxLine.To;
                        initialPts.Add(new InitialPt(pointToSeg, itSegments[i].Line.UnitTangent, perpVec));
                    }
                }
            }
Ejemplo n.º 3
0
            //main
            public void SetMainAxis(Polyline boundary)
            {
                Line alignMain = SetEachMainAxis(AlignGuide, boundary);
                Line perpMain  = PCXTools.PCXLongest(Pt, boundary, PerpGuide);

                if (alignMain.Length > perpMain.Length)
                {
                    MainAxis = alignMain;
                    SubAxis  = perpMain;
                }

                else
                {
                    MainAxis = perpMain;
                    SubAxis  = alignMain;
                }
            }
Ejemplo n.º 4
0
        public static bool IsIntersect(Line line1, Line line2, bool checkCoincidence)
        {
            //seive1: xRange
            double xHi1 = Math.Max(line1.FromX, line1.ToX);
            double xLo1 = Math.Min(line1.FromX, line1.ToX);
            double xHi2 = Math.Max(line2.FromX, line2.ToX);
            double xLo2 = Math.Min(line2.FromX, line2.ToX);

            if (xHi1 > xHi2)
            {
                if (xLo1 > xHi2)
                {
                    return(false);
                }
            }

            if (xHi2 > xHi1)
            {
                if (xLo2 > xHi1)
                {
                    return(false);
                }
            }

            //seive2: yRange
            double yHi1 = Math.Max(line1.FromY, line1.ToY);
            double yLo1 = Math.Min(line1.FromY, line1.ToY);
            double yHi2 = Math.Max(line2.FromY, line2.ToY);
            double yLo2 = Math.Min(line2.FromY, line2.ToY);

            if (yHi1 > yHi2)
            {
                if (yLo1 > yHi2)
                {
                    return(false);
                }
            }

            if (yHi2 > yHi1)
            {
                if (yLo2 > yHi1)
                {
                    return(false);
                }
            }

            //intersect check
            Point3d crossPt = GetCrossPt(line1, line2);

            if (crossPt == Point3d.Unset && checkCoincidence) //colinear check
            {
                if (PCXTools.IsPtOnLine(line2.From, line1, 0.5))
                {
                    return(true);
                }

                if (PCXTools.IsPtOnLine(line2.To, line1, 0.5))
                {
                    return(true);
                }

                return(false);
            }


            if (!checkCoincidence)  //end point check
            {
                if (crossPt.DistanceTo(line1.From) < 0.5)
                {
                    return(false);
                }

                if (crossPt.DistanceTo(line1.To) < 0.5)
                {
                    return(false);
                }

                if (crossPt.DistanceTo(line2.From) < 0.5)
                {
                    return(false);
                }

                if (crossPt.DistanceTo(line2.To) < 0.5)
                {
                    return(false);
                }
            }

            if (!PCXTools.IsPtOnLine(crossPt, line1, 0.5))
            {
                return(false);
            }

            if (!PCXTools.IsPtOnLine(crossPt, line2, 0.5))
            {
                return(false);
            }

            return(true);
        }