2
$\begingroup$

I was wondering how do you find the best fit bezier curve between two points with known tangents as in the most minimum curve of which the two handle points are not known.

Most guides explain how to calculate the curve of something like this:

enter image description here

But in my scenario i don't know P1 or P2 i only know P0 and P3 and their tangents that govern the direction of travel like so:

enter image description here

Is it possible to calculate a minimum bezier curve with such information, how would you find the curve in this situation ?

$\endgroup$
3
  • 1
    $\begingroup$ Do the relative norms of your tangents have a meaning to take into account, or do you consider them as just indicating a direction (unit norm) ? $\endgroup$ – Jean Marie Jun 14 at 22:45
  • $\begingroup$ The tangents are just normalised directions for some object to travel along the curve (think like a road segment). $\endgroup$ – WDUK Jun 14 at 23:05
  • $\begingroup$ Therefore, in the absence of other constraints, it is the second solution of my answer which is valid: take for $P_1$ any point on the line defined by $P_0$ and direction given by $V_0$. The same for $P_2$ $\endgroup$ – Jean Marie Jun 14 at 23:08
4
$\begingroup$

The same question (Find the cubic bezier control points from end points and tangents) had been asked some time ago but with no validated answer.

It is well known that if we denote by $V_0$ (resp. $V_1$) the initial (resp. final) vector, we have:

$$V_0=3\vec{P_0P_1}=3(P_1-P_0) \ \iff \ P_1=P_0+\frac13 V_0$$

and:

$$V_1=3\vec{P_2P_3}=3(P_3-P_2) \ \iff \ P_2=P_3-\frac13 V_1$$

(Proof below).

If the norms of the vectors are unimportant, you can multiply them resp. by arbitrary constants $k_0, k_1$ giving, instead of (1),(2), the more general solutions:

$$P_1=P_0+k_0V_0$$

and

$$P_2=P_3-k_1V_1$$

Briefly said: take for $P_1$ any point on the line defined by $P_0$ and direction given by $V_0$. The same for $P_2$.

Proof for (1) and (2): the current point on the cubic Bezier is:

$$P_t=s^3P_0+3s^2tP_1+3st^2P_2+t^3P_3 \ \text{with} \ s:=1-t$$

The speed vector is: $$V_t=dP_t/dt=-3(1-t)^2P_0+3(1-4t+3t^2)P_1+3(2t-3t^2)P_2+3t^2P_3$$

If the given vectors $V_0$ and $V_1$ are interpreted as speed vectors, taking $t=0$ (resp. $t=1$) gives

$$V_0=-3P_0+3P_1=3\vec{P_0P_1} \ \ \text{and} \ \ V_1=-3P_2+3P_3=3\vec{P_2P_3}$$

$\endgroup$
7
  • $\begingroup$ Does $V_n$ represent the normalised tangents at each end point or something else? $\endgroup$ – WDUK Jun 14 at 23:07
  • $\begingroup$ Yes, they do... $\endgroup$ – Jean Marie Jun 14 at 23:08
  • $\begingroup$ Okay thanks ! :) $\endgroup$ – WDUK Jun 14 at 23:08
  • 1
    $\begingroup$ FWIW, you can see a demo of this technique in Python in my answer here: astronomy.stackexchange.com/a/28036/16685 Sorry, the code's a bit cryptic, but it uses the "1/3 rule" with velocity vectors at each point to build a series of 3D Bézier curves. $\endgroup$ – PM 2Ring Jun 14 at 23:16
  • 2
    $\begingroup$ I have added a proof of the relationship between $P_0P_1$ and $V_0$, and between $P_2P_3$ and $V_1$ if the vectors are interpreted as speed vectors. $\endgroup$ – Jean Marie Jun 14 at 23:24
3
$\begingroup$

There are an infinite number of Bézier curves that satisfy your constraints. In the answer from @Jean Marie, you can use any values you like for $k_0$ and $k_1$ (though you probably will be happier if you use positive values).

To choose a “good” curve, you have to tell us what additional properties you want.

If you don't care very much about the shape of the curve, the simplest idea is to choose $P_1$ so that the distance from $P_0$ to $P_1$ is 1/3 of the distance from $P_0$ to $P_3$, and similarly for $P_2$. This will at least prevent cusps or loops or extraneous inflexion in the curve, and will reproduce straight lines nicely.

Another way to produce a “nice” Bézier curve is to pretend that it’s a conic and then minimize its eccentricity. This is much more complex that the simple “1/3” rule described above, but it will sometimes produce better curves (in some sense). The details are explained here:

John C. Femiani, Chia-Yuan Chuang, Anshuman Razdan,
Least eccentric ellipses for geometric Hermite interpolation,
Computer Aided Geometric Design,
Volume 29, Issue 2, 2012, Pages 141-149.

$\endgroup$
1
$\begingroup$

I believe what you want to do can be achieved by the "Optimized Geometric Hermite Curve" mentioned in this paper.

Basically, you will use a cubic Hermite curve to interpolate the given position and first derivative vector at the end points. A cubic Hermite curve is defined by two end points and two tangent vectors at the end points. In this paper's case (which is the same as your case), the tangent vectors are only known for their directions and their magnitudes are determined by minimizing the "bending energy" of the curve, which will result in a pretty smooth curve.

The formula for the tangent vector's magnitudes $a^*_0$ and $a^*_1$ is listed as equation (4) in the paper.

$\endgroup$
5
  • $\begingroup$ That does look like roughly ideal but the paper and the math involved is way beyond me unfortunately as per usual for most papers lol. $\endgroup$ – WDUK Jun 16 at 6:05
  • $\begingroup$ You can simply use the formula listed as eq(4) without the need to understand how it is derived. $\endgroup$ – fang Jun 16 at 6:31
  • $\begingroup$ Not sure i understand the return value though, equation (4) returns two scalars a and a* (which is making me think of complex conjugate). Should it not be giving me two vectors which would act as the two control points for the bezier curve? $\endgroup$ – WDUK Jun 16 at 20:35
  • $\begingroup$ The a0* and a1* are the magnitudes for the tangent vectors at the start and end of the curve. Since you have the direction (which is an unit vector) for the tangent vectors, multiplying them with a0* and a1* will give you the tangent vectors, from which you can find the two control points P1 and P2. $\endgroup$ – fang Jun 17 at 1:43
  • $\begingroup$ Ah i see, thanks :) I will give it a try. $\endgroup$ – WDUK Jun 17 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.