如何获得二维几何中包含的所有点? [英] How to get all points contained inside a 2d geometry?

查看:55
本文介绍了如何获得二维几何中包含的所有点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将所有点包含在二维几何体中?

如何知道一个点是否包含二维几何?

我需要一个内置的顺便说一下,不是复杂的数学。

How to get all points contained inside a 2d geometry?
How to know whether a point is contained withing a 2d geometry or not?
I need a built-in way, not complex math.

推荐答案

我的假设:

- 你对2D场景感兴趣

- 你有一组N分(只有在N> 3的情况下才有用)



这个2D的一般解决方案是:

确定点集的凸包。怎么做你可以找到,例如 https://en.wikipedia.org/wiki/Quickhull [ ^ ]



每个点都不在结果中凸壳在里面。凸包的点是在边界。



你可以扩展3D场景。



我希望它有所帮助。

问候
My assumptions:
- You are interesting in a 2D Scenario
- You have a set of N points (only intersting in case N > 3)

A General solution for this 2D is:
Determine the convex hull for your set of Points. How to do that you can find e.g. https://en.wikipedia.org/wiki/Quickhull[^]

Every Point which is not in the result of the convex hull is inside. Points of the convex hull are "at the border".

You can that extend also for 3D Scenarios.

I hope it helps.
Regards


您的问题没有解决方案。


您希望的功能非常专业,您不会在通用框架中找到它。



您的唯一方法是编写复杂的自我编程或查找代码示例。

或多或少,您必须将2D任意几何转换为具有一些特殊数学属性的几何,以便检查是否有点是否内部。

- 转换是将几何体分解成许多凸起部分

- 该点必须位于其中一个部分内。
There is no solution to your question the way you want.

The function you wishes is highly specialized and you will not find it in a general purpose framework.

Your only way is to program complex math your self or find examples of code.
More or less, you have to transform your 2D arbitrary geometry into a geometry that have some special math properties that allow to check if a point is inside or not.
- the transform is to break the geometry into many convex parts
- the point have to be inside one of the parts.


是的,这是可能的。

Geometry.FillContains方法(Point) [ ^ ]

积分变量是2d几何中包含的所有点的列表(geom)。

代码:

Yes, it is possible.
Geometry.FillContains Method (Point)[^]
"points" variable is a list of all points contained within a 2d geometry (geom).
Code:
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.Loaded += MainWindow_Loaded;
    }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        RectangleGeometry rectgeom = new RectangleGeometry(new Rect(0, 0, 10, 10));
        Geometry geom = rectgeom;

        List<Point> points = GetPoints(geom); // Points contained within a 2d geometry
    }

    private List<Point> GetPoints(Geometry geom)
    {
        List<Point> points = new List<Point>();

        for (int i1 = 0; i1 < 100; i1++)
            for (int i2 = 0; i2 < 100; i2++)
                if (geom.FillContains(new Point(i1, i2))) points.Add(new Point(i1, i2));

        return points;
    }
}


这篇关于如何获得二维几何中包含的所有点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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