none
"Intersect" - What can it and can it not be used with? RRS feed

  • Question

  • I see "Intersect" often being used with "Rectangles", often to detect collision.

    Can Intersect only be used with Rectangles, or can I use it with images too?  Maybe even classes, if I have a number of different things that I would like to all have an Intersect case... do I need to add the Intersect case individually to each image I use?

    Thursday, November 26, 2015 5:56 PM

Answers

  • I see "Intersect" often being used with "Rectangles", often to detect collision.

    Can Intersect only be used with Rectangles, or can I use it with images too?  Maybe even classes, if I have a number of different things that I would like to all have an Intersect case... do I need to add the Intersect case individually to each image I use?

    Hi,

    in WindowsForms, collision detection is usually done with looking for intersections of regions or one region and one GraphicsPath. That way you can get collsions for non-rectangular shaped objects in a correct way (consider two balls, when you looking for the bound-rexts intersecting, you'd get false positives)

    An example: [Dont worry about whats done with the collisions, its a bit of physics - the basic technique to determine collisons is shown in the Colldides method of the Ball class]

    https://onedrive.live.com/redir.aspx?cid=d5e5bd21dbf5e4e9&resid=D5E5BD21DBF5E4E9!4365&parId=D5E5BD21DBF5E4E9!1450&authkey=!

    For images, get the outline of the drawn stuff and setup a GraphicsPath with it. For other shaped things, do the same.

    Regards,

      Thorsten




    Thursday, November 26, 2015 6:57 PM
  • Hi,

    I also found this the VisualTreeHelper.FindElementsInHostCoordinates(Point, UIElement) method:

    https://msdn.microsoft.com/en-us/library/windows/apps/br243040.aspx

    and the VisualTreeHelper.FindElementsInHostCoordinates(Rect, UIElement) method

    https://msdn.microsoft.com/en-us/library/windows/apps/br243041.aspx

    With this, it seems you can test points or rects to get all UIElements that contain that point. I think you could use that too for determining collisions.  But maybe it then would be better to just use some GraphTheory and some LinearAlgebra to implement it your own...

    For curvy structures you would need to implement a flatten method (approximating the curve by lines) then though.

    Regards,

      Thorsten




    Friday, November 27, 2015 4:36 PM

All replies

  • I see "Intersect" often being used with "Rectangles", often to detect collision.

    Can Intersect only be used with Rectangles, or can I use it with images too?  Maybe even classes, if I have a number of different things that I would like to all have an Intersect case... do I need to add the Intersect case individually to each image I use?

    Hi,

    in WindowsForms, collision detection is usually done with looking for intersections of regions or one region and one GraphicsPath. That way you can get collsions for non-rectangular shaped objects in a correct way (consider two balls, when you looking for the bound-rexts intersecting, you'd get false positives)

    An example: [Dont worry about whats done with the collisions, its a bit of physics - the basic technique to determine collisons is shown in the Colldides method of the Ball class]

    https://onedrive.live.com/redir.aspx?cid=d5e5bd21dbf5e4e9&resid=D5E5BD21DBF5E4E9!4365&parId=D5E5BD21DBF5E4E9!1450&authkey=!

    For images, get the outline of the drawn stuff and setup a GraphicsPath with it. For other shaped things, do the same.

    Regards,

      Thorsten




    Thursday, November 26, 2015 6:57 PM
  • Is it possible to classify a number of images into one class, then use an intersect or collide case to define all of them?

    Or do I place the method in each individual image?

    Thursday, November 26, 2015 7:08 PM
  • By the way, does it matter if I am using XAML instead of WinForms?

    I currently am using a Universal Windows with XAML

    Thursday, November 26, 2015 7:59 PM
  • By the way, does it matter if I am using XAML instead of WinForms?

    I currently am using a Universal Windows with XAML

    Yes that matters a lot. In WPF you can use the HiTest method for visuals. In that new UI stuff I dont know...

    https://msdn.microsoft.com/en-us/library/ms608753%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

    https://msdn.microsoft.com/en-us/library/ms752097%28v=vs.100%29.aspx



    Thursday, November 26, 2015 8:07 PM
  • Hi,

    I looked a bit around. As far as I see there's the intersect and contains methods...

    https://blogs.windows.com/buildingapps/2015/04/09/how-to-make-a-windows-store-game-with-c-and-xaml-part-3/

    Regards,

      Thorsten

    Thursday, November 26, 2015 8:17 PM
  • HI.

    System.Drawing.Region.Intersect(Region)

    Region can construct from almost every shape.

    https://msdn.microsoft.com/en-us/library/b1a3xbhd%28v=vs.110%29.aspx


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Friday, November 27, 2015 9:37 AM
  • Hi,

    I also found this the VisualTreeHelper.FindElementsInHostCoordinates(Point, UIElement) method:

    https://msdn.microsoft.com/en-us/library/windows/apps/br243040.aspx

    and the VisualTreeHelper.FindElementsInHostCoordinates(Rect, UIElement) method

    https://msdn.microsoft.com/en-us/library/windows/apps/br243041.aspx

    With this, it seems you can test points or rects to get all UIElements that contain that point. I think you could use that too for determining collisions.  But maybe it then would be better to just use some GraphTheory and some LinearAlgebra to implement it your own...

    For curvy structures you would need to implement a flatten method (approximating the curve by lines) then though.

    Regards,

      Thorsten




    Friday, November 27, 2015 4:36 PM