拡張線分を(y切片、勾配)または同様のものとしてパラメータ化することができます。与えられた線分と交差する延長線の間隔は、線が点であるかのように照会できる(y切片、勾配)空間の形を形成します。
rectの境界線セグメントのいずれかと交差する線の和集合を取ってから、それらが延長されていないときに実際に矩形を横切っていないセグメントをフィルタリングして除外します。
// we will intersect against three of the rect's borders (the 4th's results are redundant)
borders = {(TopLeft, TopRight), (TopRight, BottomRight), (BottomRight, BottomLeft)}
// each border forms a shape in (y, slope) space defined by two intersecting half spaces
// we query the line space using something standard like kd-trees
lines1 = Union(borders.ForEach(LineSpace.Inside(ShapeOfSegmentInIntersectSpace(?border))))
// now filter out lines that don't cross the rect when extended
// since we already know they intersect when extended, the check is pretty simple
lines2 = lines1.Where(?line.BoundingRect.Intersects(rect))
あなた自身で作成してみませんか?それはまっすぐ私に見えます。 –
"落ち込む"とは、セグメントが長方形と交差することを意味しますか? –
さて、交差は1つのケースであり、もう1つはセグメントが矩形内にentierlyである場合です –