命中测试曲线的一部分 [英] Hit test a part of curve

查看:67
本文介绍了命中测试曲线的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GraphicsPath绘制曲线:

I draw a curve using GraphicsPath:

GraphicsPath gp = new GraphicsPath();
gp.AddCurve(new Point[]{ new Point(10,30), new Point(50,60), new Point(100,30)
});
...



我知道IsOutlineVisible方法可以确定曲线上是否存在点.但是问题是我想确切地知道该点位于曲线的哪一部分.例如,从点(10,30)到(50,60)或从(50,60)到(100,30).

有没有人有一个或两个主意可以帮助我将脑筋包扎在这个主意上?

谢谢!



I know IsOutlineVisible method to determine whether or not a point lies on the curve. But the problem is I want to know exactly which part of curve the point lies on. For example, from point (10,30) to (50,60) or from (50,60) to (100,30).

Does anyone have an idea or two to help me wrap my brain around this one?

Thanks!

推荐答案

尝试使用:

try using:

Rectnagle RectangleFromPoints(Point A, Point B)//method 1
{
//Finish this method...
}


int[] PointOnCurveBetween(Point P, GraphicsPath gp)//Method 2
{
    for(int i=1;i<gp.pointlist.Length; i++)
    {
        if(RectangleFromPoints(
              gp.Points[i-1],gp.Points[i]).Contains(P))
        { return new int[]{i,i-1};}

    }
}




至少这是想到的第一种方法..如果您知道曲线的方向(或者您可以在方法1中确定每个序列的导数,并使用switch/if语句),效果最好. br/>
仅当函数为1-1并且表现良好时,此函数才能可靠地工作.


或者,如果您知道"他们正在单击曲线本身(不会造成用户错误),则可以对每个线段进行最小二乘回归,然后对R值最高的线段进行排序. -这是更严格的方法,但是会比方法1.慢.(您也可以通过使用平面几何/三角函数来对此进行综合,但是由于慢"的Math.(blah)函数可能会大大慢一些. .

-顺便说一句,如果您使用最小二乘法,则无需占用sqrt,只需将数字保留为大",然后将它们进行比较,答案仍将相同.-有时您不需要精确地做数学.


-我做过类似的事情,您可能想尝试一种节点"方法,将线段分为2个端点和一个中心,每个端点都带有一个圆,将它们围绕在圆周上,等于线段距离的0.25,这样您就可以使用树并快速获得更接近"的答案,然后使用更严格的方法来确定正确"的答案.

-祝你好运.




At least that is the first way that comes to mind.. would work best if you knew the direction of the the curve(or you could determine the derivative of each sequence in method 1, and use switch/if statements)...

this will only work reliably when the function is 1-1 and somewhat well behaved.


alternativly if you "know" that they are clicking on the curve itself(no tollerance for user error ) you can do a least squares regression to each line segment, and then sort for the segment with the highest R value. -- this is more rigiourus, however will be slower then Method 1..(you could acomplist this also by using plane geometry/trigonometry, however that may be significantly slower due to the Math.(blah) functions which are "slow"..

--Incidently if you do use the least squares approach you wouldn''t need to take the sqrt, just leave the numbers "big" and compare them the answer will still be the same.--Sometimes you don''t need to be precise to do math.


-- I did something similar and you may want to try a "Node" approach, where you seperate the line segment into 2 ends and a center, each with a circle arround them equal to .25 the distance of the segment, this way you use a tree and get"closer" answers fast and then use more rigourus methods to determine the"correct" answer.

-good luck.


这篇关于命中测试曲线的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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