找到一对QuadCurve2D的交点 [英] Find the intersection(s) of a pair of QuadCurve2Ds

查看:147
本文介绍了找到一对QuadCurve2D的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来近似两个 QuadCurve2D 实例相交的点(如果有的话)?



也就是说,如何计算此图中红点的坐标?在 QuadCurve2D 中没有明显的方法来做到这一点。 $ b



(注意:不是精确的,因为我已经为图表手动调整了它们,还要注意即使位于(无限)抛物线上也不在曲线段上的缺失第四点。)



这两个曲线段使用以下代码创建:

  QuadCurve2D curve1 =新QuadCurve2D.Double(-2.00 ,-2.00,+ 0.75,+ 4.75,+ 2.00,-0.75); 
QuadCurve2D curve2 =新的QuadCurve2D.Double(-2.50,-0.75,+5.50,-0.50,+0.50,+1.25);

注2:我也希望能够相交直线&一个二次曲线,但我认为这可以通过设置其中一个控制点与端点共线来处理。 解决方案

取决于您是否对近似或精确的解决方案感兴趣(达到双精度)。对于近似值,你可以简单地将曲线参数化为一些函数 ),然后进行一些间隔嵌套来找到 t 的值最小化曲线之间的距离。



对于确切的解决方案,您必须找到两个圆锥曲线相交的四个点。关于此维基百科上有一段简短的内容。本书投影几何透视有更详细的解释细节。当然有各种语言的实现可用; Asymptote的,刚刚出现在我的脑海里。其一般情况下的实施看起来相当可怕,所以可能是他们在那里做了太复杂的事情。



一旦你有了所有的四个交点,你仍然会必须决定它们中的哪一个位于由QuadCurve的端点划定的圆锥曲线部分,但这应该比较简单。总之,您需要执行以下三个步骤:


  1. 从端点和控制点计算圆锥曲线剖面部分

  2. 使用铅笔中的简并元素相交圆锥曲线截面
  3. 决定这些交点是否在端点之间

如果您在其中一个步骤的数学细节上遇到问题,最好在数学堆栈交换。不仅人们在解决数学问题方面有更多的经验,MathJax排版数学的功能将使答案更加可读,而不仅仅是这里可能会有的答案。



在你的笔记2中关于直线:这很容易,因为如果你用坐标来表达这个问题,你只会得到一个二次方程,而不是等式4的方程,一般问题,如果按照上述参考文献所述解决问题,仍然是3级。人们可以这样写一般方法,即将圆锥曲线与直线相交只是解决方案中的一个步骤,因此为此提供一种方法可能效果不错。


Is there an easy way to approximate the points (if any) where two instances of QuadCurve2D intersect?

That is, how could I compute the coordinates of the red dots in this diagram? There is no obvious method in QuadCurve2D to do this.

(note: the points are not exact as I have tweaked them manually for the diagram. Also note the "missing" fourth point which does not lie on the curve segment even though it lies on the (infinite) parabola.)

These two curve segments were created with the following code:

QuadCurve2D curve1 = new QuadCurve2D.Double(-2.00, -2.00, +0.75, +4.75, +2.00, -0.75);
QuadCurve2D curve2 = new QuadCurve2D.Double(-2.50, -0.75, +5.50, -0.50, +0.50, +1.25);

Note 2: I would also like to be able to intersect a straight line & a quadratic curve, but I assume this can be handled by setting one of the control points to be colinear with the endpoints.

解决方案

Depends on whether you're interested in approximate or in exact solutions (up to double precision). For approximate ones, you could simply parametrize the curves as some function f(t) and then do some interval nesting to find values for t which minimize the distance between the curves.

For exact solutions, you'd have to find the four points where two conic sections intersect. There is a short paragraph about this on wikipedia. The book Perspectives on Projective Geometry has a longer section explaining the details. There certainly are implementations available for various languages; the one for Asymptote comes to my mind just now. The implementation for its general case looks quite frightening, though, so it might be they are doing something overly complicated there.

Once you have all four points of intersection, you'd still have to decide which of them are on the part of the conic section delimited by the endpoints of your QuadCurve, but that should be simple in comparison. So in total, you'd have these three steps:

  1. Compute matrix of conic sections section from endpoints and control points
  2. Intersect conic sections using degenerat elements in their pencil
  3. Decide whether these intersections lie between the endpoints

If you have a problem with the mathematical details of one of these steps, it might be better to ask on the mathematics stack exchange. Not only have people there more experience with solving mathematical problems, the MathJax features for typesetting math will make the answers far more readable than an answer here could hope to be.

As to your note 2 about the straight line: that is easier by far, because if you express that problem in terms of coordinates, you'd only end up with a quadratic equation, instead of an equation of degree 4 for the naive approach to the general problem, and still degree 3 if you solve it as described by the above references. One can write the general aproach in such a way that intersecting a conic with a line is a step in the solution, so having a method for this might work well enough.

这篇关于找到一对QuadCurve2D的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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