如何在C#中减去两个形状并获得新形状的结果点? [英] How can I subtract two shapes and get resulting points of the new shape in C#?

查看:86
本文介绍了如何在C#中减去两个形状并获得新形状的结果点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个2D形状的(x,y)点,可能是任何类型的多边形,但大多数是矩形。小矩形位于大矩形内部,并始终与其圆周相切。我想(以编程方式)减去它们并获得新多边形的结果(x,y)点(但不在屏幕上)。



任何人都可以提供任何有关我如何实现这一目标的线索吗?



我有什么尝试过:



我试图使用System.Windows.Media.Geometry.Combine方法,但老实说我不明白它是如何工作的在我的情况下。

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.

推荐答案

将你的点转换为一个区域(最简单的方法是通过GraphicsPath或Rectangle)你可以使用各种方法获得一个新的形状:

地区类(System.Drawing)| Microsoft Docs [ ^ ]

它包括有用的方法,如Intersect,Union和Exclude。
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.


这篇关于如何在C#中减去两个形状并获得新形状的结果点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆