Path points in xaml

Asked

Viewed 51 times

4

I am creating an application that will make an agent walk through an area with various obstacles as shown in the figure.

inserir a descrição da imagem aqui

The agent will walk from point S to point G, passing only through the vertices of the polygons. How can I catch the vertices of the polygons in XAML and C#? Polygons were made in Path and are inside a Canvas.

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:AgentesDeBusca"
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="AgentesDeBusca.MainWindow"
    mc:Ignorable="d"
    Title="Agentes de Busca" Height="720" Width="1024" MinHeight="720" MinWidth="1024">

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="150"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="painelDireito" Margin="10,30" Grid.Column="0">
        <TextBlock>Busca:</TextBlock>
        <Button Margin="0,10" Content="Largura" Click="Button_Click"/>
        <Button Padding="5" Content="Profundidade"/>
    </StackPanel>
    <Grid x:Name="painelEsquerdo" Margin="10" Grid.Column="1">
        <Canvas>
        <Path x:Name="Figura1" Data="M135.41667,86 L57.916338,173.5 76.916001,258.5 158.91598,281.5 191.91597,170.5 z" Height="214.004" Stretch="Fill" Stroke="Black" Width="188.05" Margin="81.1,53.498,0,251.498" HorizontalAlignment="Left" d:LayoutOverrides="Width"/>
        <Path Data="M232.41667,96 L202.91634,238.5 267.91513,237.5 z" Stretch="Fill" Stroke="Black" Width="91.936" Margin="255.157,121.76,0,240.957" HorizontalAlignment="Left" d:LayoutOverrides="Width"/>
        <Rectangle Height="84.948" Stroke="Black" Width="334.312" Canvas.Left="86.616" Canvas.Top="297.039" HorizontalAlignment="Left" Margin="85.084,0,0,98.552" VerticalAlignment="Bottom" d:LayoutOverrides="Height"/>
        <Path Data="M227.41631,43 L277.91614,32.5 317.91538,64.5 227.91631,143.5 z" Height="121.977" Stretch="Fill" Stroke="Black" Canvas.Left="343.618" Canvas.Top="30.215" Margin="323.396,40,441.397,0" VerticalAlignment="Top" d:LayoutOverrides="Height"/>
        <Rectangle Height="190" Stroke="Black" Canvas.Left="493.362" Canvas.Top="37.839" Width="144.868" Margin="0,53,283,0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
        <Path Data="M290.91475,212.18682 L335.91574,467.31869 371.91682,347.94506 z" Height="119.799" Stretch="Fill" Stroke="Black" Width="114.223" Canvas.Left="399.337" Canvas.Top="210.457" Margin="398.013,242.6,380.013,156.6"/>
        <Path Data="M524.41667,39 L492.49935,65.5 549.49932,251.5 550.49919,72.5 z" Height="232.518" Stretch="Fill" Stroke="Black" Width="82.185" Canvas.Left="661.214" Canvas.Top="31.304" HorizontalAlignment="Right" Margin="0,53.498,177.672,232.984" d:LayoutOverrides="Width"/>
        <Path Data="M472.91622,381.5 L413.74494,437.32002 414.91561,538.5 470.91599,584.5 522.91637,535.5 520.91604,428.5 z" Height="222.172" Stretch="Fill" Stroke="Black" Canvas.Left="584.363" Canvas.Top="233.328" Width="153.464" HorizontalAlignment="Right" Margin="0,0,193.549,28.358" VerticalAlignment="Bottom"/>
        <Ellipse x:Name="Agente" Height="5" Stroke="Black" Width="5" Canvas.Left="55.444" Canvas.Top="345.271" Fill="Red" HorizontalAlignment="Left" Margin="69.125,0,0,133" VerticalAlignment="Bottom" d:LayoutOverrides="Width, Height"/>
        <Ellipse Height="8" Stroke="Black" Width="8" Canvas.Left="55.444" Canvas.Top="345.271" Fill="Black" HorizontalAlignment="Right" Margin="0,0,67.125,53.5" VerticalAlignment="Bottom" d:LayoutOverrides="Width, Height"/>
        <TextBlock x:Name="textBlock" Height="21" TextWrapping="Wrap" Text="S" Width="10" Canvas.Left="40" Canvas.Top="345" FontSize="18.667" RenderTransformOrigin="2.091,2.588" HorizontalAlignment="Left" Margin="52,0,0,117" VerticalAlignment="Bottom" d:LayoutOverrides="Width"/>
        <Ellipse Fill="Black" Height="5" Stroke="Black" Width="5" Canvas.Left="761.799" Canvas.Top="37.839" HorizontalAlignment="Right" Margin="0,63,158.625,0" VerticalAlignment="Top" d:LayoutOverrides="Width, Height"/>
        <TextBlock x:Name="textBlock1" Height="22.038" TextWrapping="Wrap" Text="G" Width="20.643" FontSize="18.667" Canvas.Left="770.774" Canvas.Top="23" HorizontalAlignment="Right" Margin="0,63,127.803,0" VerticalAlignment="Top"/>
        </Canvas>
    </Grid>

    <TextBlock Grid.Column="1" Grid.Row="1" Margin="10" FontSize="14">Propriedades:</TextBlock>
</Grid>

1 answer

1

This is a case of Path Find trying to use the A* algorithm (it is one of the simplest, however there are others more efficient) where each pixel will be a house and the pixels filled with the black color are obstacles. link: Simple example in C#

  • Thank you for your reply, but that’s not exactly what I asked for! Path in XAML(WPF) is a picture. What I want is to find the vertices of these figures.

  • Thank you for the explanation and good luck with the answer, I will prefer your question because the subject interested me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.