//public void SetSlope(ref List <CEdge > CEdgeLt) //{ // CGeoFunc.SetSlope(ref CEdgeLt); //} /// <summary>Detect the intesection between two edges</summary> /// <returns >the intersection point</returns> /// <remarks>the edges have to be set slope before using this function /// If the two edges overlap, then the IntersectCpt is the point with larger XY coordinate of the two ends of the overlap line segment /// </remarks> public void DetectIntersection() { CEdge cedge1 = _CEdge1; CEdge cedge2 = _CEdge2; cedge1.JudgeAndSetSlope(); cedge2.JudgeAndSetSlope(); CPoint IntersectCpt = null; CEdge overlapcedge = null; CEnumIntersectionType penumIntersectionType = CEnumIntersectionType.NoNo; if (cedge1.blnHasSlope == true && cedge2.blnHasSlope == true) //this is the normal case { //if (CCmpMethods.Cmp(cedge1.dblSlope, cedge2.dblSlope)==0) //parallel if (CCmpMethods.CmpDbl_ConstVerySmall(cedge1.dblSlope, cedge2.dblSlope) == 0) //parallel { if (CCmpMethods.CmpDbl_CoordVerySmall(cedge1.dblYIntercept, cedge2.dblYIntercept) == 0) //parallel and with the same YIntercept { penumIntersectionType = DetectIntersectionParralel(cedge1, cedge2, out IntersectCpt, out overlapcedge); } else //parallel but not with the same YIntercept { penumIntersectionType = CEnumIntersectionType.NoNo; } } else //not parallel { penumIntersectionType = DetectIntersectionNormal(cedge1, cedge2, out IntersectCpt); } } else if (cedge1.blnHasSlope == true && cedge2.blnHasSlope == false) { penumIntersectionType = DetectIntersectionOneNoSlope(cedge1, cedge2, out IntersectCpt); } else if (cedge1.blnHasSlope == false && cedge2.blnHasSlope == true) { penumIntersectionType = DetectIntersectionOneNoSlope(cedge2, cedge1, out IntersectCpt); penumIntersectionType = ReverseIntersectionType(penumIntersectionType); } else if (cedge1.blnHasSlope == false && cedge2.blnHasSlope == false) { if (CCmpMethods.CmpDbl_CoordVerySmall(cedge1.FrCpt.X, cedge2.FrCpt.X) == 0) //parallel and with the same X Coordinate { penumIntersectionType = DetectIntersectionParralel(cedge1, cedge2, out IntersectCpt, out overlapcedge); } else //parallel but not with the same X Coordinate { penumIntersectionType = CEnumIntersectionType.NoNo; } } _enumIntersectionType = penumIntersectionType; _IntersectCpt = IntersectCpt; _OverlapCEdge = overlapcedge; }
public CIntersection(CEdge cedge1, CEdge cedge2, CPoint pIntersectCpt, CEdge pOverlapCEdge, CEnumIntersectionType penumIntersectionType) { _CEdge1 = cedge1; _CEdge2 = cedge2; _IntersectCpt = pIntersectCpt; _OverlapCEdge = pOverlapCEdge; _enumIntersectionType = penumIntersectionType; }
/// <summary> /// QueryMovedPt /// </summary> /// <param name="dblRatioforMovePt">the ratio of length1 (start point to target point) to length2 (start point to end point) on a base line</param> /// <param name="dblLengthforMovePt">the distance of the original point (on the polyline) to the targest point (on the base line)</param> /// <param name="dblAngleDiffforMovePt">the angle difference of segment1 (target point to original point) and segment2 (target point to end point)</param> /// <param name="dblProp">t</param> /// <param name="intID">ID of the original point</param> /// <returns></returns> public CPoint QueryMovedPt(double dblRatioforMovePt, double dblLengthforMovePt, double dblAngleDiffforMovePt, double dblProp, int intID) { double dblAngle = _dblAxisAngle - dblAngleDiffforMovePt; CPoint targetcpt = CGeoFunc.GetInbetweenCpt(_FrCpt, _ToCpt, dblRatioforMovePt); double dblresultLength = (1 - dblProp) * dblLengthforMovePt; double dblresultX = targetcpt.X + dblresultLength * Math.Cos(dblAngle); double dblresultY = targetcpt.Y + dblresultLength * Math.Sin(dblAngle); return(new CPoint(intID, dblresultX, dblresultY)); }
public static bool IsVertexIntersection(CPoint cpt) { if (cpt.IncidentCEdge.indexID == cpt.IncidentCEdge.GetLargerAxisAngleCEdge().GetLargerAxisAngleCEdge().indexID) { return(false); } else { return(true); } }
///// <summary> ///// 指定点沿着曲线到起点的距离 ///// </summary> ///// <param name="pPoint">待计算的点</param> ///// <param name="pPolyline">点所在的曲线</param> ///// <param name="blnasRatio">指定计算相对距离还是绝对距离</param> ///// <returns></returns> //public double CalDistanceFromStartPoint(IPoint pPoint, bool blnasRatio) //{ // IPoint outPoint = new PointClass(); // double distanceAlongCurve = 0;//该点在曲线上最近的点距曲线起点的距离 // double distanceFromCurve = 0;//该点到曲线的直线距离 // bool bRightSide = false; // this.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pPoint, blnasRatio, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref bRightSide); // return distanceAlongCurve; //} /// <summary> /// /// </summary> /// <param name="distanceAlongCurve"></param> /// <param name="distanceFromCurve"></param> /// <param name="bRightSide"></param> /// <returns>the point</returns> //public CPoint QueryPointByDistances(double distanceAlongCurve, bool basRatioAlong, double distanceFromCurve, bool bRightSide) //{ // ILine pNomalLine = new LineClass(); // this._pLine.QueryNormal(esriSegmentExtension.esriExtendEmbedded, //distanceAlongCurve, basRatioAlong, distanceFromCurve, pNomalLine); // //this.SetEmpty(); // IPoint outpoint = new PointClass(); // if (bRightSide == true) // { // pNomalLine.QueryPoint(esriSegmentExtension.esriNoExtension, 1, true, outpoint); // } // else // { // pNomalLine.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1, true, outpoint); // } // CPoint cpt = new CPoint(0, outpoint); // return cpt; //} /// <summary> /// you must setlength before using this function /// </summary> public double QueryPtHeight(CPoint querycpt) { if (this.blnHasSlope == true) { return(Math.Abs(this.dblYIntercept + this.dblSlope * querycpt.X - querycpt.Y) * this.dblValueForDis); } else { return(Math.Abs(querycpt.X - this.FrCpt.X)); } }
/// <summary> /// 通过折线上两节点获取该折线的子折线 /// </summary> /// <param name="cpt1">需获取的子折线上的终点之一</param> /// <param name="cpt2">需获取的子折线上的终点之一 2</param> public CPolyline GetSubPolyline(CPoint cpt1, CPoint cpt2) { CPolyline subcpl = GetSubPolyline(cpt1.ID, cpt2.ID); if (subcpl.FrCpt.Equals2D(cpt1) == false || subcpl.ToCpt.Equals2D(cpt2) == false) { MessageBox.Show("there is a problem in GetSubPolyline!"); } return(subcpl); }
private bool DetermineIsTouch(CEdge cedge1, CEdge cedge2, ref CPoint IntersectCpt) { if (IsOnCEdge(IntersectCpt, cedge1) == false || IsOnCEdge(IntersectCpt, cedge2) == false) { return(false); } else { return(true); } }
private static bool IsOnCEdge(CPoint cpt, CEdge cedge) { if (CCmpMethods.IsInbetween(cpt.X, cedge.FrCpt.X, cedge.ToCpt.X) == false || CCmpMethods.IsInbetween(cpt.Y, cedge.FrCpt.Y, cedge.ToCpt.Y) == false) { return(false); } else { return(true); } }
//public CptEdgeDis() //{ //} public CptEdgeDis(double dbldis = 0, double dblt = -1, CPoint frcpt = null, CEdge frcedge = null, CPoint tocpt = null, CEdge tocedge = null, bool blnheight = false) { this.GID = _intStaticGID++; this.dblDis = dbldis; this.t = dblt; this.FrCpt = frcpt; this.FrCEdge = frcedge; this.ToCpt = tocpt; this.ToCEdge = tocedge; this.blnHeight = blnheight; }
/// <summary> /// Initializes a new cedge instance /// </summary> /// <param name="eFrCpt">Start cedge vertex index</param> /// <param name="eToCpt">End cedge vertex index</param> public CEdge(CPoint eFrCpt, CPoint eToCpt, bool isSetLength = false) { this.GID = _intStaticGID++; _FrCpt = eFrCpt; _ToCpt = eToCpt; _intIncrease = eToCpt.Compare(eFrCpt); if (isSetLength == true) { SetLength(); } }
/// <summary> /// Initializes a new instance of a triangle /// </summary> /// <param name="point1">Vertex 1</param> /// <param name="point2">Vertex 2</param> /// <param name="point3">Vertex 3</param> public CTriangle(int intTID, CPoint point1, CPoint point2, CPoint point3) { List <CPoint> cptlt = new List <CPoint>(3); cptlt.Add(point1); cptlt.Add(point2); cptlt.Add(point3); _CptLt = cptlt; _intTID = intTID; FormCEdge(cptlt); FormPolygon(cptlt); }
public static void ShowEdgeRelationshipAroundCpt(CPoint cpt) { CEdge IncidentCEdge = cpt.IncidentCEdge; CEdge currentcedge = IncidentCEdge; Console.WriteLine("-------------------------------start Around Cpt------------------------------"); do { CDCEL.ShowEdgeRelationship(currentcedge); currentcedge = currentcedge.GetLargerAxisAngleCEdge(); } while (IncidentCEdge.dblAxisAngle != currentcedge.dblAxisAngle); Console.WriteLine("-------------------------------end Around Cpt------------------------------"); }
private CEnumIntersectionType DetectIntersectionParralelIncrease(CEdge cedge1, CEdge cedge2, out CPoint IntersectCpt, out CEdge overlapcedge) { if (CCmpMethods.CmpCptXY(cedge1.ToCpt, cedge2.ToCpt) <= 0) //we compare both x and y so that we can handle two edges which have no slope { return(DetectIntersectionParralelIncreaseCEdge2Righter(cedge1, cedge2, out IntersectCpt, out overlapcedge)); } else { CEnumIntersectionType enumIntersectionType = DetectIntersectionParralelIncreaseCEdge2Righter(cedge2, cedge1, out IntersectCpt, out overlapcedge); return(ReverseIntersectionType(enumIntersectionType)); } }
private CEnumIntersectionType DetectIntersectionParralel(CEdge cedge1, CEdge cedge2, out CPoint IntersectCpt, out CEdge overlapcedge) { CEdge auxCEdge1 = cedge1; bool blnReversed1 = false; if (CCmpMethods.CmpCptXY(cedge1.FrCpt, cedge1.ToCpt) == 1) { auxCEdge1 = new CEdge(cedge1.ToCpt, cedge1.FrCpt); blnReversed1 = true; } CEdge auxCEdge2 = cedge2; bool blnReversed2 = false; if (CCmpMethods.CmpCptXY(cedge2.FrCpt, cedge2.ToCpt) == 1) { auxCEdge2 = new CEdge(cedge2.ToCpt, cedge2.FrCpt); blnReversed2 = true; } CEnumIntersectionType penumIntersectionType = DetectIntersectionParralelIncrease(auxCEdge1, auxCEdge2, out IntersectCpt, out overlapcedge); if (penumIntersectionType == CEnumIntersectionType.FrTo || penumIntersectionType == CEnumIntersectionType.ToFr) //besides, penumIntersectionType coud be CEnumIntersectionType.NoNo or CEnumIntersectionType.Overlap { string substr1 = penumIntersectionType.ToString().Substring(0, 2); string substr2 = penumIntersectionType.ToString().Substring(2, 2); if (blnReversed1 == true) { substr1 = ReverseEnd(substr1); } if (blnReversed2 == true) { substr2 = ReverseEnd(substr2); } string strIntersectionType = substr1 + substr2; return((CEnumIntersectionType)Enum.Parse(typeof(CEnumIntersectionType), strIntersectionType)); } return(penumIntersectionType); }
private bool FindCorrCptInSDByTinNode(ITinNode pTinNode, SortedDictionary <CPoint, CPoint> CptSD, out CPoint outcpt) { CPoint tincpt = new CPoint(pTinNode); bool isFound = CptSD.TryGetValue(tincpt, out outcpt); if (isFound == false) { Console.WriteLine("cannot find a point" + tincpt.X + " " + tincpt.Y + " " + " of a TinNode in: " + this.ToString() + ".cs "); double dblOriginaldblVerySmall = CConstants.dblVerySmallCoord; do { CConstants.dblVerySmallCoord = CConstants.dblVerySmallCoord * 10; isFound = CptSD.TryGetValue(tincpt, out outcpt); } while (isFound == false); CConstants.dblVerySmallCoord = dblOriginaldblVerySmall; } return(isFound); }
/// <summary> /// Makes a planar checks for if the points is spatially equal to another point. /// </summary> /// <param name="other">Point to check against</param> /// <returns>True if X and Y values are the same</returns> public bool Equals2D(CPoint other) { return(CCmpMethods.ConvertCmpToBool(CCmpMethods.CmpCptYX(this, other))); }
/// <summary> /// /// </summary> /// <param name="cpt"></param> /// <param name="newcedge">newcedge should have a twin edge</param> public static void InsertCEdgeAtCpt(CPoint cpt, CEdge newcedge) { var SmallerAxisAngleCEdge = FindSmallerAxisAngleCEdgebyCEdge(cpt, newcedge, false); InsertCEdgeBySmaller(SmallerAxisAngleCEdge, newcedge); }
public CPolyline(int intID, CPoint cpt1, CPoint cpt2, bool blnSetPolyline = false) : this(intID, CHelpFunc.MakeLt <CPoint>(cpt1, cpt2), blnSetPolyline) { }
/// <summary> /// Makes a planar checks for if the points is spatially equal to another point. /// </summary> /// <param name="other">Point to check against</param> /// <returns>True if X and Y values are the same</returns> public bool Equals2D(CPoint other, double dblVerySmall) { return(CCmpMethods.ConvertCmpToBool(CCmpMethods.CmpCptYX(this, other))); }
private CEnumIntersectionType DetectIntersectionParralelIncreaseCEdge2Righter(CEdge cedge1, CEdge cedge2, out CPoint IntersectCpt, out CEdge overlapcedge) { IntersectCpt = null; overlapcedge = null; if (CCmpMethods.CmpCptXY(cedge1.ToCpt, cedge2.FrCpt) == -1) //we compare both x and y so that we can handle two edges haveing no slope { return(CEnumIntersectionType.NoNo); } else if (CCmpMethods.CmpCptXY(cedge1.ToCpt, cedge2.FrCpt) == 0) //we compare both x and y so that we can handle two edges haveing no slope { IntersectCpt = cedge1.ToCpt; return(CEnumIntersectionType.ToFr); } else // if (CCmpMethods.CmpXY(cedge1.ToCpt, cedge2.FrCpt) == 1) //we compare both x and y so that we can handle two edges haveing no slope { CPoint frcpt = null; if (CCmpMethods.CmpCptXY(cedge1.FrCpt, cedge2.FrCpt) == 1) //we compare both x and y so that we can handle two edges haveing no slope { frcpt = cedge1.FrCpt; } else { frcpt = cedge2.FrCpt; } //overlapcedge = new CEdge(frcpt, cedge1.ToCpt); //to save memory, we don't record the overlapcedge IntersectCpt = cedge1.ToCpt; return(CEnumIntersectionType.Overlap); } }
///// <summary>whether a point is in cedge (we already know that the point is on the line that goes through the cedge)</summary> ///// <returns> -1, nonsense, ///// 1, this point is not on the Edge ///// 2, this point is the FrCpt ///// 3, this point is in the Edge ///// 4, this point is the ToCpt</returns> ///// <remarks></remarks> /// <summary> /// /// </summary> /// <param name="cpt"></param> /// <param name="cedge"></param> /// <returns> "No", "Fr", "In", "To"</returns> public static string InCEdge(CPoint cpt, CEdge cedge) { //we test both x and y. if we only test one coordinate, we may get wrong result. // for example, there is an intersection that is actually in an edge, and this edge is almost vertical. // if we only test the x coordinate, then we will get that the intersection is the end (on the boundary) of this edge // because we use dblVerysmall to judge //cedge.SetLength(); int intCompareX = CCmpMethods.CmpThreeCoord(cpt.X, cedge.FrCpt.X, cedge.ToCpt.X); int intCompareY = CCmpMethods.CmpThreeCoord(cpt.Y, cedge.FrCpt.Y, cedge.ToCpt.Y); //the result is a result of a 6*6 matrix string strInCEdge = ""; if (intCompareX == 1 || intCompareX == 5 || intCompareY == 1 || intCompareY == 5) //this point is not on the Edge { strInCEdge = "No"; } else if (intCompareX == 3 || intCompareY == 3) //this point is in the Edge { strInCEdge = "In"; } else // if (intCompareX, intCompareY = 0, 2, 4), //this point is one of the ends of the Edge { if (intCompareX == 0) { if (intCompareY == 0 || intCompareY == 2) { strInCEdge = "Fr"; } else //if (intCompareY==4) { strInCEdge = "To"; } } else if (intCompareX == 2) { if (intCompareY == 0 || intCompareY == 2) { strInCEdge = "Fr"; } else //if (intCompareY==4) //unfortunately, this can happen!!! { //MessageBox.Show("This cannot happen! InCEdge!"); // strInCEdge = "In"; } } else //if (intCompareX == 4) { if (intCompareY == 0 || intCompareY == 4) { strInCEdge = "To"; } else //if (intCompareY==2) { //MessageBox.Show("This cannot happen! InCEdge!"); strInCEdge = "In"; } } } return(strInCEdge); }
//public CEdge GetEdgeIncrease() //{ // int intCompare = CCmpMethods.Cmp(_FrCpt, _ToCpt); // if (intCompare<=0) // { // return this; // } // else // { // return new CEdge (_ToCpt,_FrCpt); // } //} public double CalInbetweenCptProportion(CPoint cpt) { return(CGeoFunc.CalInbetweenCptProportion(cpt, _FrCpt, _ToCpt)); }
public CPolyline(int intID, CPoint cpt, bool blnSetPolyline = false) : this(intID, CHelpFunc.MakeLt(cpt), blnSetPolyline) { }
/// <summary> ///the intersection of two line segments. The two segments both have slope and not parrallel /// </summary> private CEnumIntersectionType DetectIntersectionNormal(CEdge cedge1, CEdge cedge2, out CPoint IntersectCpt) { IntersectCpt = new CPoint(-1); //the intersection of the two lines, not the two line segments IntersectCpt.X = (cedge2.dblYIntercept - cedge1.dblYIntercept) / (cedge1.dblSlope - cedge2.dblSlope); IntersectCpt.Y = IntersectCpt.X * cedge1.dblSlope + cedge1.dblYIntercept; return(DetermineIntersectCase(cedge1, cedge2, ref IntersectCpt)); }
/// <summary> /// /// </summary> /// <param name="cedge1"></param> /// <param name="cedge2"></param> /// <param name="IntersectCpt"></param> /// <returns></returns> private CEnumIntersectionType DetermineIntersectCase(CEdge cedge1, CEdge cedge2, ref CPoint IntersectCpt) { string strInCEdge1 = InCEdge(IntersectCpt, cedge1); string strInCEdge2 = InCEdge(IntersectCpt, cedge2); //to save memory, we always use the original points if the intersection overlaps an original point //we set the intersection to null if there is no intersection if (strInCEdge1 == "No" || strInCEdge2 == "No") { IntersectCpt = null; } else if (strInCEdge1 == "Fr") { IntersectCpt = cedge1.FrCpt; } else if (strInCEdge1 == "To") { IntersectCpt = cedge1.ToCpt; } else //if(strInCEdge1 == "In") { if (strInCEdge2 == "Fr") { IntersectCpt = cedge2.FrCpt; } else if (strInCEdge2 == "To") { IntersectCpt = cedge2.ToCpt; } else //if(strInCEdge2 == "In") { //IntersectCpt = IntersectCpt; } } if (strInCEdge1 == "No" || strInCEdge2 == "No") { return(CEnumIntersectionType.NoNo); //do we really need do this seperately? } else { string strIntersectionType = strInCEdge1 + strInCEdge2; return((CEnumIntersectionType)Enum.Parse(typeof(CEnumIntersectionType), strIntersectionType)); } }
/// <summary>Detect the intesection between two edges</summary> private CEnumIntersectionType DetectIntersectionOneNoSlope(CEdge cedge, CEdge cedgeNoSlope, out CPoint IntersectCpt) { IntersectCpt = new CPoint(-1); //the intersection of the two lines, not the two line segments IntersectCpt.X = cedgeNoSlope.FrCpt.X; IntersectCpt.Y = IntersectCpt.X * cedge.dblSlope + cedge.dblYIntercept; return(DetermineIntersectCase(cedge, cedgeNoSlope, ref IntersectCpt)); }
public void SetOuterFaceCptlt(bool clockwise = true, bool blnIdentical = true, CPoint StartPositionCpt = null) { this.CptLt = GetOuterCptEb(clockwise, blnIdentical, StartPositionCpt).ToList(); }
public IEnumerable <CPoint> GetOuterCptEb(bool clockwise = true, bool blnIdentical = true, CPoint StartPositionCpt = null) { var pOuterCmptCEdge = _OuterCmptCEdge; if (pOuterCmptCEdge == null) { throw new ArgumentException("Super face does not have an outer ring!"); } if (StartPositionCpt != null) { pOuterCmptCEdge = TraverseToGetCorrectCEdgeComponent(pOuterCmptCEdge, StartPositionCpt); } if (clockwise == true) //for an outer path, the edges are stored counter-clockwise in DCEL { foreach (var cpt in TraverseToGetCptEb(pOuterCmptCEdge, false)) { yield return(cpt); } } else { foreach (var cpt in TraverseToGetCptEb(pOuterCmptCEdge, true)) { yield return(cpt); } } if (blnIdentical == true) { yield return(pOuterCmptCEdge.FrCpt); } }
public CEdge DetectCloestLeftCorrectCEdge(CPoint cpt) { CGeoFunc.DetectCloestLeftCEdge(cpt, _pEdgeGrid); return(CGeoFunc.GetCorrectEdge(cpt)); }
/// <summary> /// /// </summary> /// <param name="cedgeComponent"></param> /// <param name="blnNext"></param> /// <returns></returns> private static CEdge TraverseToGetCorrectCEdgeComponent(CEdge cedgeComponent, CPoint cpt) { var currentcedge = cedgeComponent; do { if (CCmpMethods.CmpCptYX(currentcedge.FrCpt, cpt) == 0) { return(currentcedge); } currentcedge = currentcedge.cedgeNext; } while (currentcedge.GID != cedgeComponent.GID); throw new ArgumentException("we cannot find an appropriate edge!"); }