How I can calculate the normal vector for two dimensional Bézier curve?
(I have the control points of the curve in the x y plane)
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
(x,y) is a tangent vector of your curve, then the normal vector is simply
(y,-x). So you just need to find a tangent vector, and it all depends on how exactly you define the curve.
If your curve comes from a parametric representation
p(t) = (x(t),y(t)) which is sufficiently continuous, then a good approximation of the tangent vector at
t is, given a very small
p(t+ɛ)-p(t) v(t) = ——————————— ɛ x(t+ɛ)-x(t) y(t+ɛ)-y(t) v(t) = ( ——————————— , ——————————— ) ɛ ɛ
This applies to e.g. Bézier curves.
If your curve comes from a dense list of points then a good approximation comes from taking the two closest points on the curve,
p1, and then your tangent is:
v(t) = (p1 - p0) / distance(p1, p0)
If your curve comes from a scattered list of points then the above method will probably exhibit too many discontinuities, but so will your curve unless you use some kind of interpolation. What I suggest is consider the interpolation function (for instance, cubic interpoltion) as a parametric function, and apply the first method.