This is a migrated thread and some comments may be shown as answers.

check for shape intersection/overlap

5 Answers 343 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Turian
Top achievements
Rank 1
Turian asked on 22 Mar 2013, 12:51 AM
Hi,

How do I check if selectedItem intersects or overlap other shape on mouseUp?

5 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 25 Mar 2013, 05:03 PM
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.

0
Turian
Top achievements
Rank 1
answered on 26 Mar 2013, 12:54 PM
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?
0
Petar Mladenov
Telerik team
answered on 29 Mar 2013, 07:44 AM
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.

0
Artem
Top achievements
Rank 1
answered on 05 Nov 2016, 01:22 PM
could you pleas provide an example of how to use these methods to check overlapping?
0
Petar Mladenov
Telerik team
answered on 09 Nov 2016, 12:06 PM
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!
Tags
Diagram
Asked by
Turian
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Turian
Top achievements
Rank 1
Artem
Top achievements
Rank 1
Share this question
or