3

I have the start and end points and the values of the slope of the curve at those points. Now I have to draw a "smooth 2D bezier curve" through the two given points. Now how to locate the two control points to achieve this. Is there any way for it? I know that the control points must lie on the tangents at the respective start and end points.

  • Note:By "smooth curve", I meant that there should be no steep curves or turnings in the final plot.
helloflash
  • 2,457
  • 2
  • 15
  • 19
Chinni
  • 1,199
  • 1
  • 14
  • 28

2 Answers2

2

It sounds like you have catmull-rom curve coordinates (two points, and their departure and arrival tangents), in which case https://pomax.github.io/bezierinfo/#catmullconv covers all the math necessary to convert those to Bezier coordinates. And if you don't care about the "how", just skip to the end of the section for the straight up conversion rules.

tl;dr version: rewrite your coordinates to Catmull form:

[P1, v1, v2, P2] -> [P1 - v1, P1, P2, P2 + v2]

Then we convert that to Bezier coordinates:

P1 <= P1
p2 <= P1 - (P2 - P1 - v1) / 6 * f
p3 <= P2 + (P2 + v2 - P1) / 6 * f
p4 <= P2

the f is a tension constant. Play around with that. It's usually 1, but it might not be depending on how strong those tangents were.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • Hi, basically I am a newbie in this area. Can you please provide me with good links on "catmull-rom curves". Thank you @Mike'Pomax'Kamermans – Chinni Sep 16 '14 at 14:14
  • they're in the same family of curves as Bezier curves (Which is why they can convert to each other), but they're defined as "coordinates" that the curve goes through, and the "speed" (i.e. tangent) at which you go through each coordinate. Unlike Bezier curves, using Catmull-Rom form always ensures your curve passes through your coordinates but it's harder to free-model with. http://www.mvps.org/directx/articles/catmull/ might be useful, but you should be able to find more articles on them with some websearches – Mike 'Pomax' Kamermans Sep 16 '14 at 15:16
0

For a cubic Bezier curve defined by P0, P1, P2 and P3 where P0 and P3 are the start point and end point, its first derivative vector at t=0 and t=1 are

C'(t=0) = 3*(P1-P0)
C'(t=1) = 3*(P3-P2)

So, if you already know the slope at the start and end point, you can easily convert that to tangent vectors and find the control points P1 and P2. You do need to assign a proper magnitude for the first derivative vectors so that the final resulting curve does not have inflection point. But as long as you make sure the resulting control polygon formed by P0, P1, P2 and P3 are convex, then your cubic Bezier curve should be smooth and has no turnnings.

fang
  • 3,473
  • 1
  • 13
  • 19
  • Thanks for your answer. I didn't think about the convex polygons.But by differentiating "C", we get 4 equations, dY/dt[t=0] = 3*(Y1-Y0) dY/dt[t=1] = 3*(Y3-Y2) dX/dt[t=0] = 3*(X1-X0) dX/dt[t=1] = 3*(X3-X2) But what I know is slopes of curves at P0 and P1 i.e t=0 and t=1. Say dY/dX[t=0] = m0 dY/dX[t=1] = m1, which yield (Y1-Y0)/(X1-X0)=m0 and (Y3-Y2)/(X3-X2)=m1 which are trivial. – Chinni Sep 16 '14 at 18:39
  • @ChiCha: Please note that the slope only specify the direction of the tangent vector and not the magnitude. So, you cannot solve the value of (X1, Y1) and (X2, Y2) from (Y1-Y0)/(X1-X0)=m0 and (Y3-Y2)/(X2-X2)=m1. What you should do is to convert slopes into unitized tangent vectors. For example, slope m0 can be converted to unitized tangent vector (1, m0)/Sqrt(1+m0*m0). Once you have unitize tangent vector, assigning an arbitrary magnitude to it and you can solve for P1 and P2 using the two equations in my post. You can adjust the shape of the curve by changing the tangent vector magnitude. – fang Sep 16 '14 at 19:34