public bool L_C_LineInCircle(G_Line L1, G_Cricle C1)
        {
            bool   isStartPtInCircle = false;
            bool   isEndPtInCircle   = false;
            double dist;

            dist = Math.Sqrt(Math.Pow(C1.pCenter.X - L1.startPt.X, 2) + Math.Pow(C1.pCenter.Y - L1.startPt.Y, 2));
            if (dist < C1.radius)
            {
                isStartPtInCircle = true;
            }

            dist = Math.Sqrt(Math.Pow(C1.pCenter.X - L1.endPt.X, 2) + Math.Pow(C1.pCenter.Y - L1.endPt.Y, 2));
            if (dist < C1.radius)
            {
                isEndPtInCircle = true;
            }

            if (isStartPtInCircle && isEndPtInCircle)
            {
                return(true);
            }

            return(false);
        }
        public bool L_C_Intesect(G_Line L1, G_Cricle C1)
        {
            bool   isStartPtInCircle = false;
            bool   isEndPtInCircle   = false;
            double dist;

            dist = Math.Sqrt(Math.Pow(C1.pCenter.X - L1.startPt.X, 2) + Math.Pow(C1.pCenter.Y - L1.startPt.Y, 2));
            if (dist < C1.radius)
            {
                isStartPtInCircle = true;
            }

            dist = Math.Sqrt(Math.Pow(C1.pCenter.X - L1.endPt.X, 2) + Math.Pow(C1.pCenter.Y - L1.endPt.Y, 2));
            if (dist < C1.radius)
            {
                isEndPtInCircle = true;
            }

            if (isStartPtInCircle && !isEndPtInCircle)
            {
                return(true);
            }
            if (!isStartPtInCircle && isEndPtInCircle)
            {
                return(true);
            }

            //穿过circle的情况
            if (!isEndPtInCircle && !isStartPtInCircle)
            {
                dist = System.Math.Sqrt(System.Math.Abs(L1.k * C1.pCenter.X - C1.pCenter.Y + L1.b) / (System.Math.Pow(L1.k, 2) + 1));
                if (dist < C1.radius)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public void refreshConstraint(StrokeGroup sg)
        {
            bool isL_L_Vertical     = false;
            bool isL_L_Intersect    = false;
            bool isL_L_Parallel     = false;
            bool isL_C_Tangent      = false;
            bool isL_C_Intersect    = false;
            bool isL_C_LineInCircle = false;

            //TODO::加入更多的约束关系


            if (sg.GRAPH == Graphic.Line)
            {
                G_Line geo1 = (G_Line)sg.geometry;

                foreach (SKContextDGNode nd in sketch.sketchContextDG.DGNodeList)
                {
                    Graphic type = nd.strokeGroup.GRAPH;

                    switch (type)
                    {
                    case Graphic.Line:      //L_L
                        G_Line geo2 = (G_Line)nd.strokeGroup.geometry;
                        if (geo2 != null)
                        {
                            isL_L_Vertical  = new G_L_L_Constraints().L_L_Vertical(geo1, geo2);
                            isL_L_Intersect = new G_L_L_Constraints().L_L_Intersect(geo1, geo2);
                            isL_L_Parallel  = new G_L_L_Constraints().L_L_Parallel(geo1, geo2);
                            //保存约束
                            ConstraintElement elem = new ConstraintElement();
                            elem.strokeGroup1 = sg;
                            elem.strokeGroup2 = nd.strokeGroup;
                            if (isL_L_Intersect)
                            {
                                elem.ctype = ConstraintType.Intersect;
                                sketch.m_pConsList.Add(elem);
                                // MessageBox.Show("Intersecting");
                            }
                            if (isL_L_Parallel)
                            {
                                elem.ctype = ConstraintType.Parallel;
                                sketch.m_pConsList.Add(elem);
                                //  MessageBox.Show("Parallel");
                            }
                            if (isL_L_Vertical)
                            {
                                elem.ctype = ConstraintType.Vertical;
                                sketch.m_pConsList.Add(elem);
                                //  MessageBox.Show("Vertical");
                            }
                        }
                        break;

                    case Graphic.Circle:      //L_C
                        G_Cricle geo3 = (G_Cricle)nd.strokeGroup.geometry;
                        if (geo3 != null)
                        {
                            isL_C_Tangent      = new G_L_C_Constraints().L_C_Tangent();
                            isL_C_Intersect    = new G_L_C_Constraints().L_C_Intesect(geo1, geo3);
                            isL_C_LineInCircle = new G_L_C_Constraints().L_C_LineInCircle(geo1, geo3);
                            //保存约束
                            ConstraintElement elem1 = new ConstraintElement();
                            elem1.strokeGroup1 = sg;
                            elem1.strokeGroup2 = nd.strokeGroup;
                            if (isL_C_Tangent)
                            {
                                elem1.ctype = ConstraintType.Tangent;
                                sketch.m_pConsList.Add(elem1);
                                // MessageBox.Show("Intersecting");
                            }
                            if (isL_C_Intersect)
                            {
                                elem1.ctype = ConstraintType.Intersect;
                                sketch.m_pConsList.Add(elem1);
                                //  MessageBox.Show("Parallel");
                            }
                            if (isL_C_LineInCircle)
                            {
                                elem1.ctype = ConstraintType.In;
                                sketch.m_pConsList.Add(elem1);
                                //  MessageBox.Show("Vertical");
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            if (sg.GRAPH == Graphic.Circle)    //Circle
            {
                G_Cricle geo4 = (G_Cricle)sg.geometry;

                foreach (SKContextDGNode nd in sketch.sketchContextDG.DGNodeList)
                {
                    Graphic type = nd.strokeGroup.GRAPH;
                    switch (type)
                    {
                    case Graphic.Line:         //L_C
                        G_Line geo5 = (G_Line)nd.strokeGroup.geometry;
                        if (geo5 != null)
                        {
                            isL_C_Tangent      = new G_L_C_Constraints().L_C_Tangent();
                            isL_C_Intersect    = new G_L_C_Constraints().L_C_Intesect(geo5, geo4);
                            isL_C_LineInCircle = new G_L_C_Constraints().L_C_LineInCircle(geo5, geo4);
                            //保存约束
                            ConstraintElement elem1 = new ConstraintElement();
                            elem1.strokeGroup1 = sg;
                            elem1.strokeGroup2 = nd.strokeGroup;
                            if (isL_C_Tangent)
                            {
                                elem1.ctype = ConstraintType.Tangent;
                                sketch.m_pConsList.Add(elem1);
                                // MessageBox.Show("Intersecting");
                            }
                            if (isL_C_Intersect)
                            {
                                elem1.ctype = ConstraintType.Intersect;
                                sketch.m_pConsList.Add(elem1);
                                //  MessageBox.Show("Parallel");
                            }
                            if (isL_C_LineInCircle)
                            {
                                elem1.ctype = ConstraintType.In;
                                sketch.m_pConsList.Add(elem1);
                                //  MessageBox.Show("Vertical");
                            }
                        }
                        break;

                    case Graphic.Circle:         //C_C
                        break;

                    default:
                        break;
                    }
                }
            }
        }