예제 #1
0
        public              Vector3d[] GetIntersections(Triangle triangle)
        {
            // 3本の線分と平面との交差判定に還元する
            var intersections = new HashSet <string>();

            var lineSegments =
                new [] {
                new LineSegment(triangle.Point0, triangle.Point1),
                new LineSegment(triangle.Point1, triangle.Point2),
                new LineSegment(triangle.Point2, triangle.Point0)
            };

            var result = new List <Vector3d>();

            for (var i = 0; i < lineSegments.Length; ++i)
            {
                var tempIntersection = GetIntersection(lineSegments[i]);
                if (tempIntersection.HasValue)
                {
                    var key = Approximation.ToApproximatedString(tempIntersection.Value);
                    if (intersections.Add(key))
                    {
                        result.Add(tempIntersection.Value);
                    }
                }
            }

            return(result.ToArray());
        }
예제 #2
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);
        }