在 List(of Point) 中查找当前 y 的 2 个 x 值 [英] Find 2 x values of the current y in a List(of Point)

查看:35
本文介绍了在 List(of Point) 中查找当前 y 的 2 个 x 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个List(of PointF).2 个嵌套的 for 循环穿过一个围绕圆形(或圆形(但实际上是封闭路径))拉伸的矩形.我想使用 GetPixel(x,y) 在这个圈子内工作.这意味着,我需要相应 y 的相应最小和最大 x 值.我怎样才能用这个 List(Of PointF) 解决这个问题?我在这里请求帮助的原因是因为我对这些 List.Find(predicates or matching)things.

I have a List(of PointF). 2 nested for loops run through a rectangle that is stretched around a circle (or circle-ish (but is really is a closed path)). I want to work within this circle with GetPixel(x,y). That means, I need the respective minimum and maximum x value of the respective y. How can I work that out with this List(Of PointF)? The reason I'm requesting help here is because I get confused with these List.Find(predicates or matches)things.

For x As Integer = CInt(xmin) To CInt(xmax) Step 1
            For y As Integer = CInt(ymin) To CInt(ymax) Step 1
                'get the min and max value of x here
            Next      
Next

它是关于:我写了一个程序,使用灰度图像和拉普拉斯来执行边缘检测.用鼠标绘制一个矩形,并在其中搜索边缘.然后创建了 Drawing2D.GraphicsPath.根据照片中显示的对象,这或多或少地工作得很好,因为矩形必须相应地放大.现在我的想法是我自己绘制一个手绘 GraphicsPath(而不是矩形)并让它在其中搜索边缘.这就是为什么我有这个圆圈(或鸡蛋)并且我必须确保我不会越过它的边界.我已经可以计算出 xmin、xmax、ymin 和 ymax,但不能计算出 x1 和 x2(见图).因此,当我遍历从 xmin 到 xmax 和 ymin 到 ymax 的所有点时,我想知道当前点是否在形状内.我必须检查它的 x 值是否在给定 y 的形状 x 范围之间,然后是 y 值的相反值.那是我的问题.如何使用列表?

It's about: I wrote a program that uses gray images and Laplace to perform edge detection. A rectangle was drawn with the mouse and a search was made for edges within it. A Drawing2D.GraphicsPath was then created. This worked more or less well according to the object shown in the photo, because the rectangle had to be enlarged accordingly. Now my idea is that I draw a freehand GraphicsPath myself (instead of a rectangle) and let it search for edges within it. That's why I have this circle (or egg) and I have to make sure that I don't get over its borders. I could already work out xmin, xmax, ymin, and ymax, but not x1 and x2 (see drawing). So as I loop through all of the points from xmin to xmax and ymin to ymax, I want to know if the current point is inside the shape. I have to check whether its x value is between the shape's x range for the given y and then the reverse for the y value. That's my problem. How to use the List?

推荐答案

我认为你最好不要 For 遍历整个空间.这会奏效,但它比我认为的计算所需的工作要多.

I think you're better off not For-looping through the entire space. That would work but it's more effort than I think you need computationally.

给定一个点,要确定它是否在您的形状内(由点列表定义),您只需要将定义的点的 x 和 y 坐标与形状列表进行比较.

Given a point, to determine whether or not it is within your shape - as defined by a list of point - you should only need to compare the defined point's x and y co-ords with the shape list.

例如,给定一个点 x=100px 和 y=100px,你知道你必须检查它的 x 值是否在给定 y (100px) 的形状的 x 范围之间(或相反的 y 值).

Eg, Given a point x=100px and y=100px, you know that you have to check whether its x value is between the shape's x range for a the given y (100px) (or the reverse for the y value).

这(可能?)仅适用于不会自转"的简单形状;或具有不改变极性的曲率.(不确定它的数学名称是什么,但有一个.)例如,沙漏形状可能会带来更大的困难.

This would (probably?) only work for a simple shape that does not "turn in on itself" or has a curvature that doesn't change polarity. (Not sure what the mathematical name for that is, but there is one.) An hour-glass shape, for example, would probably present greater difficulty.

更新

这是一个简单的 Linq 方法,它确定指定的点是否在定义的形状内.请注意,它排除了形状末端上的点,但您可以通过更改>"来包含这些点.到>="等

Here's a simple Linq approach which determines whether a specified point is within a defined shape. Note that it excludes points on the extremity of the shape but you can include these by changing ">" to ">=", etc.

为简单起见,我使用八边形来近似圆.此外,代码假定位图中的所有点都是为形状定义的.也就是说,不使用插值.

For simplicity, I've used an octagon to approximate a circle. Also, the code assumes that ALL points within the bitmap are defined for the shape. That is, no interpolation is used.

    Dim s As List(Of Point) = New List(Of Point) From {New Point(50, 0), New Point(25, 25), New Point(0, 50), New Point(25, 75), New Point(50, 100), New Point(75, 75), New Point(100, 50), New Point(75, 25)}
    Dim p As Point = New Point(30, 75) ' Is inside the shape
    Dim IsInside As Boolean = s.Exists(Function(f) f.Y = p.Y AndAlso f.X < p.X) AndAlso s.Exists(Function(f) f.Y = p.Y AndAlso f.X > p.X)

可能有多种方法可以结合 Linq 测试,但您懂的.

There're probably ways to combine the Linq test, but you get the idea.

这篇关于在 List(of Point) 中查找当前 y 的 2 个 x 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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