Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have (x,y) points of two 2D shapes, which might be any type polygon but mostly rectangles. The small rectangle is inside the big one and always tangent to its circumference. I would like to subtract them (programmatically) and get resulting (x,y) points of the new polygon (but not on screen).

Can anyone give any clues on how I might accomplish this?

What I have tried:

I tried to use the System.Windows.Media.Geometry.Combine method, but to be honest I didn't understand how it works in my case.
Posted
Updated 30-Mar-19 1:08am
Comments
Patrice T 30-Mar-19 12:27pm    
"I would like to subtract them"
what do you mean by subtract ?
show a sample data and expected result.

1 solution

Convert your Points to a Region (easiest way is via a GraphicsPath or a Rectangle) and you can use the various methods to get a new "shape":
Region Class (System.Drawing) | Microsoft Docs[^]
It includes useful methods like Intersect, Union, and Exclude.
 
Share this answer
 
Comments
Mazin78 31-Mar-19 8:12am    
Thank you, I have used both (PathFigure and RectangleGeometry), and I got the new shape using:
CombinedGeometry(GeometryCombineMode.Exclude, myRectGeometry, myPathGeometry);
The issue now is how to get the points of the new shape? I don't want only to see the new shape on screen, but also I need the points for more processing.
OriginalGriff 31-Mar-19 8:25am    
The problem is that a "shape" doesn't have "Points" - it's an "area" instead - so the bare points (which are what you used to generate the shape) don't define it in any meaningful way, because bare points don't indicate "hollowness" which is the shape your description implies.

What - exactly - are you trying to use this for?
Mazin78 31-Mar-19 8:34am    
I need the points of the new shape for two reasons:
1- Exporting them to an application that draw 3D shapes based on 2D points.
2- I can use the new shape as an original one, then exclude another shape from it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900