如何计算只有起点和终点的贝塞尔曲线?
我最初发布了一个更简单(且帮助较小)的问题,并对其进行了编辑以使其更加具体。
来自维基百科的这个动画基本上显示了我想要完成的任务,但是 - 我希望将它翻转过来,它开始朝着目的地和“向上”(在此图像中)前进,然后更直接地到达终点观点。但是,我只能访问起点和终点,我希望做的是能够通过指定“高度”(或宽度,无论你想怎么称呼它)来确定其他点,以确定多高弧线确实消失了。 http://en.wikipedia.org/wiki/File:Bezier_3_big.png (由于低代表而无法发布图像)
我希望能够调用具有起点、终点和高度的函数,并让它返回曲线沿途的所有点。
帮助或指导将不胜感激。
I originally posted a much simpler (and less helpful) question, and have edited this to be more specific.
This animation from wikipedia shows basically what I want to accomplish, however - I'm hoping to have it flipped around, where it starts progressing more towards the destination and "up" (in this image), and then arcs more directly to the end point. However, I only have access to a starting point and ending point, what I am hoping to do is be able to determine the other points by specifying a "height" (or width, whatever you want to call it), to determine how high the arc actually goes.
http://en.wikipedia.org/wiki/File:Bezier_3_big.png (can't post image due to low rep)
I would like to be able to call a function with the start and end points and a height, and have it return all the points along the way of the curve.
Help or direction would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我已经完成了一个用于计算贝塞尔曲线角度并确定其各个点的博客http://johnexalt.wordpress.com/2011/05/21/bezier-curve-angle-calculation-silverlight/
下面的代码显示了如何计算贝塞尔曲线点t 的任何给定值(其中 t 的范围为 0 到 100%,并以 0-1 表示。x
= ((1 - t) * (1 - t) * p0.X) + (2 * t * (1 - t) * p1.X) + (t * t * p2.X);
//该语句用于确定曲线的x坐标。
Carlos Femmer 之前发表过一篇文章,有助于计算两点之间的角度。 http://www.carlosfemmer .com/post/2006/02/Calculate-Angle- Between-2-points-using-C.aspx。
I have wrapped up a blog for calculating Bezier curve Angle and to determine its various points in my blog http://johnexalt.wordpress.com/2011/05/21/bezier-curve-angle-calculation-silverlight/
the code below shows how to calculate the bezier curve points at any given value of t(where t ranges from 0 to 100 % and is represented in 0- 1.
x = ((1 - t) * (1 - t) * p0.X) + (2 * t * (1 - t) * p1.X) + (t * t * p2.X);
//this statement is used to determine the x coordinate of the curve.
There was a previous article given by Carlos Femmer which helps in calculating the angle between 2 points. http://www.carlosfemmer.com/post/2006/02/Calculate-Angle-between-2-points-using-C.aspx.
不失一般性,假设终点位于 x 轴上,起点位于终点的上方和左侧。
想象一下起点在悬崖顶部,终点在悬崖底部。想象一下,您从起点水平扔一个球,重力会将其向下拉,使其恰好撞到终点。
该曲线似乎具有您想要的属性。它开始时很浅,然后随着球加速而向垂直方向增加。
通过改变最初投球的角度,可以使曲线在开始时更浅。通过改变重力的强度,你可以让它最后变得更陡。
该曲线符合您的需求吗?找到这条曲线是一个非常基本的物理问题。
Without loss of generality, suppose the ending point is on the x axis and the starting point is above and to the left of the ending point.
Imagine the starting point is at the top of a cliff, and the ending point is at the bottom of a cliff. Imagine you throw a ball horizontally from the starting point, such that gravity will pull it down so that it smacks exactly into the ending point.
That curve seems to have the properties you want. It starts shallow and then increases towards the vertical as the ball accelerates.
By changing the angle at which you throw the ball initially you can make the curve more shallow at the beginning. By changing the strength of gravity you can make it more steep at the end.
Does that curve fit your needs? Finding that curve is a pretty basic physics problem.
.NET 中似乎有一种机制可以帮助您:
Graphics.DrawCurve
另外,快速的 Google 搜索发现了这些
There seems to be a mechanism in .NET that can help you:
Graphics.DrawCurve
Also, a quick Google search found these
您基本上需要一条具有三个控制点的贝塞尔曲线 - 起点、终点和中间的另一个点。
如果起点 1 为
( x1, y1 )
且终点 2 为( x2, y2 )
则从点 1 到点 2 的向量为( dx = x2-x1,dy = y2-y1)
。沿线沿 0 到 1 之间的量
along
的点是( x1 +沿 * dx, y1 + 沿 * dy )
。向量
( -dy, dx )
与直线成直角,因此如果您想偏离直线上方
的量,那么中点将是 < code>(x1 + 沿 * dx - 上方 * dy, y1 + 沿 * dy + 上方 * dx)。改变沿和上方的值,直到找到所需的倾斜曲线。
You basically want a bezier curve with three control points - the start point, the end point and another point somewhere in between.
If the start point 1 is
( x1, y1 )
and the end point 2 is( x2, y2 )
then the vector from point 1 to point 2 is( dx = x2-x1, dy = y2-y1 )
.A point along the line by an amount
along
between zero and one is( x1 + along * dx, y1 + along * dy )
.The vector
( -dy, dx )
is at right angles to the line, so if you want to go off the line by an amountabove
then the middle point would be( x1 + along * dx - above * dy, y1 + along * dy + above * dx)
.Vary the values of along and above until you find the sort of skewed curve you want.
除了起点和终点之外,您还需要描述圆弧的“角度”或曲率。贝塞尔曲线可能很好,但它们通常使用较长的点序列来实现(因为圆弧的曲率是由直线中的其他点定义的)。看看 http://en.wikipedia.org/wiki/B%C3%A9zier_curve ,在底部你可以找到一些关于“二次曲线”的信息。我敢打赌,快速谷歌搜索会给你一些实现示例。
Apart for the start-point and the end-point you need to describe the ”angle” or curvature of the arc. A Bezier curve can be good but they are usually implemented with longer sequences of points (as the curvature of the arc is defined by the other points in the line). Have a look at http://en.wikipedia.org/wiki/B%C3%A9zier_curve , at the bottom you can find some information about ”Quadratic curves”. I bet a quick google search will give you some implementation examples.