check for shape intersection/overlap

6 posts, 0 answers
  1. Turian
    Turian avatar
    2 posts
    Member since:
    Mar 2013

    Posted 21 Mar 2013 Link to this post

    Hi,

    How do I check if selectedItem intersects or overlap other shape on mouseUp?
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 25 Mar 2013 Link to this post

    Hello Turian,

     The RadDiagramShape.Bounds gives you a bounding rectangle of type Rect. The Rect type has Intersect() method which you can use in your scenario.

    Regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Turian
    Turian avatar
    2 posts
    Member since:
    Mar 2013

    Posted 26 Mar 2013 Link to this post

    Thank you for the reply.

    However, I don't want to use bound. I have polygon as RadDiagramShape. The polygon is not fully occupied the bound. Is there a way to check intersection of polygon instead of bound of polygon?
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Mar 2013 Link to this post

    Hi Turian,

     You can use the following methods from Telerik.Windows.Diagrams.Core:

    • public static bool AreLinesIntersecting(Point a, Point b, Point c, Point d, ref Point crossingPoint)
    • public static Point FindLinesIntersection(Point a, Point b, Point c, Point d, bool acceptNaN = false)
    • public static bool IntersectionPointOnEllipse(Collection<Point> points, Point org, Point end, ref Point result)
    • public static void IntersectionPointOnRectangle(Rect rectangle, Point pt1, Point pt2, ref Point intersectionPoint)
    • public static bool Intersect(Point[] points)
    • public static bool SegmentIntersect(Point s1, Point s2, Point l1, Point l2, ref Point p)
    So if you know the polygon segments of your shape, probably these methods will be helpful.
    Kind regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Artem
    Artem avatar
    3 posts
    Member since:
    Jul 2016

    Posted 05 Nov Link to this post

    could you pleas provide an example of how to use these methods to check overlapping?
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Nov Link to this post

    Hello Artem,

    The mentioned methods are coupled to shape types - if one of the two shapes is rectangle, and other is ellipse, you can foreach the sides of the rectangle in order to find IntersectionPointOnEllipse.

    Instead of posting diagram specific code here, I will try to explain that the problem is more generic. Every shape in Diagram is pretty much a Path and every shape in Diagram has Geometry property of type System.Windows.Media.Geometry. So the generic problem is how to find that two Paths or two Geometries are intersecting ? I am sure many stackoverflow, msdn forums have some suggestions on how this can be achieved. For example this one:

    Getting the intersection points of two [path] geometries in WPF

    Regards,
    Petar Mladenov
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Back to Top
UI for WPF is Visual Studio 2017 Ready