WPF路径冲突检测? [英] WPF Paths Collision detection?
本文介绍了WPF路径冲突检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个六角形
<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>
我需要检测两个六角形之间的碰撞
I need to detect collision between two hexagons
案例1(冲突)
案例2(冲突)
情况3(无碰撞)
推荐答案
You should be able to get the intersection of two Paths by the FillContainsWithDetail
method of their geometries:
var intersectionDetail = path1.Data.FillContainsWithDetail(path2.Data);
if (intersectionDetail != IntersectionDetail.NotCalculated &&
intersectionDetail != IntersectionDetail.Empty)
{
// collision
}
这篇关于WPF路径冲突检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文