# check for shape intersection/overlap

1. ##### Turian
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?
2980 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,
the Telerik team

3. ##### Turian
2 posts
Member since:
Mar 2013

Posted 26 Mar 2013 Link to this post

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?
2980 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,
the Telerik team

5. ##### Artem
3 posts
Member since:
Jul 2016

Posted 05 Nov 2016 Link to this post

could you pleas provide an example of how to use these methods to check overlapping?
2980 posts

Posted 09 Nov 2016 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,