Exemplo n.º 1
0
        /// <summary>
        /// 線分と多角形(の境界線分)の交点を取得します
        /// [契約] 線分と多角形が1つの平面上に乗っている
        /// [注意] 互いに平行な線分同士 (両者が重なる場合含む) では交点は考えません
        /// </summary>
        /// <param name="lineSegment"></param>
        /// <returns></returns>
        public List <Vector3d> GetPlanarIntersections(LineSegment lineSegment)
        {
            if (!IsValid)
            {
                return(null);
            }

            var intersections = new List <Vector3d>();
            var dicPoints     = new HashSet <string>();

            for (var i = 0; i < Points.Length; ++i)
            {
                var polygonSegment =
                    new LineSegment(Points[i],
                                    Points[(i + 1) % Points.Length]);
                var intersection =
                    polygonSegment.GetIntersection(lineSegment);
                if (!intersection.HasValue)
                {
                    continue;
                }
                var codedIntersection = Approximation.ToApproximatedString(intersection.Value);
                if (dicPoints.Add(codedIntersection))
                {
                    intersections.Add(intersection.Value);
                }
            }

            return(intersections);
        }
Exemplo n.º 2
0
 public Vector3d?GetIntersection(LineSegment lineSegment) => lineSegment.GetIntersection(this);