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_L_IntersectVertex(G_Line pFirst, G_Line pSecond) { double dist = new ToolForStroke().distanceP2P(pFirst.startPt, pSecond.startPt); if (dist < 500) { return(true); } dist = new ToolForStroke().distanceP2P(pFirst.startPt, pSecond.endPt); if (dist < 500) { return(true); } dist = new ToolForStroke().distanceP2P(pFirst.endPt, pSecond.startPt); if (dist < 500) { return(true); } dist = new ToolForStroke().distanceP2P(pFirst.endPt, pSecond.endPt); if (dist < 500) { return(true); } return(false); }
public bool L_L_Parallel(G_Line pFirst, G_Line pSecond) { //TODO::目前是两个直线的平行判定,不是两个平行线的连动约束判断; if (System.Math.Abs(pFirst.k - pSecond.k) < ParallelThreshold) { return(true); } return(false); }
public bool L_L_Intersect(G_Line pFirst, G_Line pSecond) { if (!L_L_Parallel(pFirst, pSecond)) { double tmp = (pSecond.b - pFirst.b) / (pFirst.k - pSecond.k); double ld; double rd; double mld; double mrd; if (pFirst.startPt.X < pFirst.endPt.X) { ld = pFirst.startPt.X; rd = pFirst.endPt.X; } else { ld = pFirst.endPt.X; rd = pFirst.startPt.X; } mld = ld; mrd = rd; if (pSecond.startPt.X < pSecond.endPt.X) { ld = pSecond.startPt.X; rd = pSecond.endPt.X; } else { ld = pSecond.endPt.X; rd = pSecond.startPt.X; } if (ld > mld) { mld = ld; } if (rd < mrd) { mrd = rd; } if ((tmp > mld) && (tmp < mrd)) { 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); }
//YHY-090408 public bool L_L_Vertical(G_Line pFirst, G_Line pSecond) { if (L_L_Parallel(pFirst, pSecond)) { return(false); } if ((System.Math.Abs(pFirst.angle - 90) < 0.1) && (System.Math.Abs(pSecond.angle - 0) < 0.1)) { return(true); } if ((System.Math.Abs(pFirst.angle - 0) < 0.1) && (System.Math.Abs(pSecond.angle - 90) < 0.1)) { return(true); } double tmp = pFirst.k * pSecond.k; if (System.Math.Abs(tmp + 1) < VerticalTreshold) { return(true); } return(false); }
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; } } } }