/// <summary> /// 获取相交点,如果没有,则返回null。 /// </summary> /// <param name="line">线段</param> /// <returns></returns> public TCoord GetIntersectPoint(TwoDLineSegment <TCoord> line) { TCoord val = default(TCoord); if (!this.IntersectsWith(line.Box)) { return(val); } TCoord coord = this.Left.GetIntersectionCoord(line); if (coord != null) { return(coord); } coord = this.Top.GetIntersectionCoord(line); if (coord != null) { return(coord); } coord = this.Right.GetIntersectionCoord(line); if (coord != null) { return(coord); } coord = this.Bottom.GetIntersectionCoord(line); return(coord); }
private List <TCoord> GetIntersectPoints(TwoDLineSegment <TCoord> line, TCoord outerCoord) { List <TCoord> list = new List <TCoord>(); Direction direction = GetDirection(outerCoord); switch (direction) { case Direction.East: list.Add(this.Right.GetIntersectionCoord(line)); return(list); case Direction.South: list.Add(this.Bottom.GetIntersectionCoord(line)); return(list); case Direction.North: list.Add(this.Top.GetIntersectionCoord(line)); return(list); case Direction.West: list.Add(this.Left.GetIntersectionCoord(line)); return(list); case Direction.NorthEast: TCoord coordA = this.Top.GetIntersectionCoord(line); TCoord coordB = this.Right.GetIntersectionCoord(line); if (coordA != null) { list.Add(coordA); } if (coordB != null) { list.Add(coordB); } return(list); case Direction.NorthWest: TCoord coordA1 = this.Top.GetIntersectionCoord(line); TCoord coordB1 = this.Left.GetIntersectionCoord(line); if (coordA1 != null) { list.Add(coordA1); } if (coordB1 != null) { list.Add(coordB1); } return(list); case Direction.SouthEast: TCoord coordA2 = this.Bottom.GetIntersectionCoord(line); TCoord coordB2 = this.Right.GetIntersectionCoord(line); if (coordA2 != null) { list.Add(coordA2); } if (coordB2 != null) { list.Add(coordB2); } return(list); case Direction.SouthWest: TCoord coordA3 = this.Bottom.GetIntersectionCoord(line); TCoord coordB3 = this.Left.GetIntersectionCoord(line); if (coordA3 != null) { list.Add(coordA3); } if (coordB3 != null) { list.Add(coordB3); } return(list); default: return(list); } }
/// <summary> /// 线段与盒子,可能出现1,包含,2,远离,3穿过,4相交一个边 /// </summary> /// <param name="line"></param> /// <returns></returns> public List <TCoord> GetIntersectPoints(TwoDLineSegment <TCoord> line) { List <TCoord> list = new List <TCoord>(); //1包含 if (this.Contains(line.Box)) { return(list); } //2远离 if (!this.IntersectsWith(line.Box)) { return(list); } // 4相交一个边 if (this.Contains(line.CoordA))//包含A { list.Add(line.CoordA); list.AddRange(GetIntersectPoints(line, line.CoordB)); return(list); } if (this.Contains(line.CoordB))//包含A { list.Add(line.CoordB); list.AddRange(GetIntersectPoints(line, line.CoordA)); return(list); // return GetIntersectPoints(line, line.CoordA); } //3穿过, // TCoord currentVal = default(TCoord); TCoord coordLeft = this.Left.GetIntersectionCoord(line); if (coordLeft != null) { list.Add(coordLeft); } TCoord coordTop = this.Top.GetIntersectionCoord(line); if (coordTop != null) { list.Add(coordTop); } TCoord coordRight = this.Right.GetIntersectionCoord(line); if (coordRight != null) { list.Add(coordRight); } TCoord coordbottom = this.Bottom.GetIntersectionCoord(line); if (coordbottom != null) { list.Add(coordbottom); } return(list); }
/// <summary> /// 计算两线段的交点。如果不相交,则返回null。 /// </summary> /// <param name="other">另一条线段</param> /// <returns></returns> public override XY GetIntersectionCoord(TwoDLineSegment <XY> other) { return(XyUtil.GetIntersectionPtOfTwoLineSegment(this.CoordA, this.CoordB, other.CoordA, other.CoordB)); }
/// <summary> /// 计算两线段的交点。如果不相交,则返回null。 /// </summary> /// <param name="other">另一条线段</param> /// <returns></returns> public virtual TCoord GetIntersectionCoord(TwoDLineSegment <TCoord> other) { return((TCoord)XyUtil.GetIntersectionPtOfTwoLineSegment(this.CoordA, this.CoordB, other.CoordA, other.CoordB)); // return default(TCoord); }