2011-03-15 3 views
1

다른 구분 유형 (호, 베 지어, 선분)을 사용하여 영역 셰이프를 그리려면 WPF에서 컨트롤을 만들고 복잡한 영역 셰이프를 만드는 것을 막고 싶습니다. 즉, 가장자리가 겹치는 모양을 말합니다.WPF의 PathFigure에서 세그먼트가 겹치는 지 확인하는 좋은 방법이 있습니까?

변환기로 생성 된 PathGeometry으로 작업하지만 변환기가 완료된 후 XAML은 다음 XAML처럼 보입니다. 중복이없는 경우와

: 겹침

<Path x:Name="PolygonPath" Fill="Blue" Opacity="75"> 
     <Path.Data> 
      <PathGeometry> 
       <PathGeometry.Figures> 
        <PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True"> 
         <PathFigure.Segments> 
          <QuadraticBezierSegment Point1="100,0" Point2="200,50"/> 
          <LineSegment Point="250,50"/> 
          <LineSegment Point="250,200"/> 
          <QuadraticBezierSegment Point1="100,350" Point2="50,50"/> 
         </PathFigure.Segments> 
        </PathFigure> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 

가 (검사에 실패한다) 위의 경우

<Path x:Name="PolygonPath" Fill="Blue" Opacity="75"> 
     <Path.Data> 
      <PathGeometry> 
       <PathGeometry.Figures> 
        <PathFigure StartPoint="50,50" IsClosed="True" IsFilled="True"> 
         <PathFigure.Segments> 
          <QuadraticBezierSegment Point1="100,0" Point2="200,60"/> 
          <LineSegment Point="0,60"/> 
          <LineSegment Point="250,200"/> 
          <QuadraticBezierSegment Point1="100,350" Point2="50,50"/> 
         </PathFigure.Segments> 
        </PathFigure> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 

제 2 및 제 3 선분 <LineSegment Point="0,60"/> 마지막 세그먼트 <QuadraticBezierSegment Point1="100,350" Point2="50,50"/> 오버랩 <LineSegment Point="250,200"/>.

경로가 WPF의 어느 시점에서 교차하는지 테스트하기 위해 누락 된 메서드가 있습니까?

답변

1

나는 당신이 할 수있는 것은 추측 :

호출하여이 테스트하고 각 PathFigure에 대한 경계 사각형을 얻을 :

Rect rect = new PathGeometry(new PathFigure[] { figure }).Bounds; 

그런 다음 교차 할 사각형의 확인 rect.IntersectsWith 방법을 사용합니다. 이 같은

떨어지게 :

Rect rect1 = new PathGeometry(new PathFigure[] { figure1 }).Bounds; 
Rect rect2 = new PathGeometry(new PathFigure[] { figure2 }).Bounds; 
Rect rect3 = new PathGeometry(new PathFigure[] { figure3 }).Bounds; 

if (rect1.IntersectsWith(rect2)) 
    Console.WriteLine("figure1 intersects with figure2"); 
if (rect1.IntersectsWith(rect3)) 
    Console.WriteLine("figure1 intersects with figure3"); 
if (rect2.IntersectsWith(rect3)) 
    Console.WriteLine("figure2 intersects with figure3"); 

XAML :

<Canvas> 
    <Path Stroke="Black" StrokeThickness="1"> 
     <Path.Data> 
      <PathGeometry> 
       <PathGeometry.Figures> 
        <PathFigure StartPoint="10,20" x:Name="figure1"> 
         <PathFigure.Segments> 
          <LineSegment Point="100,130"/> 
         </PathFigure.Segments> 
        </PathFigure> 
        <PathFigure StartPoint="20,70" x:Name="figure2"> 
         <PathFigure.Segments> 
          <LineSegment Point="200,70"/> 
         </PathFigure.Segments> 
        </PathFigure> 
        <PathFigure StartPoint="200,20" x:Name="figure3"> 
         <PathFigure.Segments> 
          <LineSegment Point="130,130"/> 
         </PathFigure.Segments> 
        </PathFigure> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 
</Canvas> 

반환 위의 코드 :

그림 1은 그림 2

그림 2와 교차가 교차 그림 3

01,235,164와 이 XAML

희망이 도움에 대한

는,이 나쁜 솔루션이 아니라 여러 숫자가있는 경우에만 작동

+0

을 간주한다. 여러 개의 세그먼트가있는 단일 그림으로 작업하고 있습니다. 나는 나의 질문을 더 분명히하려고 노력할 것이다. 고맙습니다. –

관련 문제