コード例 #1
0
ファイル: Corner.cs プロジェクト: 15831944/habile
        private double calcAngle(Edge end, Edge start)
        {
            Vector p1 = end.Line.getDirectionVector();
            Vector p2 = start.Line.getDirectionVector();

            if (p1 == p2)
            {
                return(Math.PI);
            }

            Line   la = new Line(end.Line.Start, start.Line.End);
            double b  = end.Line.Length();
            double c  = start.Line.Length();
            double a  = la.Length();

            double cosA    = (Math.Pow(b, 2) + Math.Pow(c, 2) - Math.Pow(a, 2)) / (2 * b * c);
            double cosAmod = Math.Max(Math.Min(cosA, 0.9999999999999), -0.9999999999999);

            double A = Math.Acos(cosAmod);

            Point ccp = la.getCenterPoint();
            Point ecp = end.Line.Offset(10).getCenterPoint();

            Line aa = new Line(ccp, ecp);
            Line bb = end.Line.extendDouble(10 * start.Line.Length());

            if (Line.hasIntersection(aa, bb))
            {
                A = 2 * Math.PI - A;
            }

            return(A);
        }
コード例 #2
0
ファイル: Region_Static.cs プロジェクト: 15831944/habile
        public static bool isPointinRegion(Point pa, Vector v, List <Line> contours)
        {
            double min_X = double.MaxValue;
            double max_X = double.MinValue;
            double min_Y = double.MaxValue;
            double max_Y = double.MinValue;

            find_boundries(contours, ref min_X, ref max_X, ref min_Y, ref max_Y);

            if (pa.X < min_X)
            {
                return(false);
            }
            if (pa.X > max_X)
            {
                return(false);
            }
            if (pa.Y < min_Y)
            {
                return(false);
            }
            if (pa.Y > max_Y)
            {
                return(false);
            }

            double dX = Math.Abs(max_X - min_X);
            double dY = Math.Abs(max_Y - min_Y);
            double dL = (dX + dY) * 2;

            double new_X = (pa.X + dX) * 5;
            double new_Y = pa.Y;

            Point pe       = pa.move(dL, v);
            Line  testLine = new Line(pa, pe);

            int i = 0;

            foreach (Line contour in contours)
            {
                bool inter = Line.hasIntersection(testLine, contour);
                if (inter)
                {
                    i++;
                }
            }

            if (i == 0)
            {
                return(false);
            }
            bool answer = (i % 2 != 0);

            return(answer);
        }
コード例 #3
0
ファイル: Region.cs プロジェクト: 15831944/habile
        public bool isPointinRegion(Point pa)
        {
            if (pa.X < min_X)
            {
                return(false);
            }
            if (pa.X > max_X)
            {
                return(false);
            }
            if (pa.Y < min_Y)
            {
                return(false);
            }
            if (pa.Y > max_Y)
            {
                return(false);
            }

            double dX = Math.Abs(max_X - min_X);
            double dY = Math.Abs(max_Y - min_Y);

            double new_X = (pa.X + dX) * 1.9;
            double new_Y = (pa.Y + dY) * 2.1;
            Point  pe    = new Point(new_X, new_Y);

            Line testLine = new Line(pa, pe);
            int  i        = 0;

            foreach (Edge edge in edges)
            {
                bool inter = Line.hasIntersection(testLine, edge.Line);
                if (inter)
                {
                    i++;
                }
            }

            if (i == 0)
            {
                return(false);
            }

            bool answer = (i % 2 != 0);

            return(answer);
        }