4

私は2つの六角形を持っています Hex1とHex2

<Path Stroke="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Fill="Red" StrokeThickness="1" Name="Hex1" Canvas.Left="31.343" Canvas.Top="26.866" Height="163.687" Stretch="Fill" Width="159.134" >
            <Path.Data>
                <PathGeometry >
                    <PathGeometry.Figures>
                        <PathFigureCollection >
                            <PathFigure StartPoint="43,0">
                                <PathFigure.Segments>
                                    <PathSegmentCollection >
                                        <PolyLineSegment Points="43,0"/>
                                        <PolyLineSegment Points="86,25"/>
                                        <PolyLineSegment Points="86,75"/>
                                        <PolyLineSegment Points="43,100"/>
                                        <PolyLineSegment Points="0,75"/>
                                        <PolyLineSegment Points="0,25"/>
                                        <PolyLineSegment Points="43,0"/>
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>
        <Path Stroke="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Fill="Aqua" StrokeThickness="1" Name="Hex2" Canvas.Left="455.224" Canvas.Top="210.448" Height="163.687" Stretch="Fill" Width="159.134" >
            <Path.Data>
                <PathGeometry >
                    <PathGeometry.Figures>
                        <PathFigureCollection >
                            <PathFigure StartPoint="43,0">
                                <PathFigure.Segments>
                                    <PathSegmentCollection >
                                        <PolyLineSegment Points="43,0"/>
                                        <PolyLineSegment Points="86,25"/>
                                        <PolyLineSegment Points="86,75"/>
                                        <PolyLineSegment Points="43,100"/>
                                        <PolyLineSegment Points="0,75"/>
                                        <PolyLineSegment Points="0,25"/>
                                        <PolyLineSegment Points="43,0"/>
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>

2つの六角形間の衝突を検出する必要があります

ケース1(衝突) ここに画像の説明を入力してください

ケース2(衝突) ここに画像の説明を入力してください

ケース3(衝突なし) ここに画像の説明を入力してください

4

1 に答える 1

7

FillContainsWithDetail2つのパスの交差を、それらのジオメトリの方法で取得できるはずです。

var intersectionDetail = path1.Data.FillContainsWithDetail(path2.Data);

if (intersectionDetail != IntersectionDetail.NotCalculated &&
    intersectionDetail != IntersectionDetail.Empty)
{
    // collision
}
于 2013-03-24T18:59:14.773 に答える