I modelled a racetrack using cubic Bézier curves. I understand that the representation is parametric: x and y vary with t. I have successfully created the cartesian coordinates thanks to this: https://blogs.mathworks.com/graphics/2014/10/13/bezier-curves/
Now I'm trying to calculate the radius of the curvature at each of the x points I have created. I would like to use this expression to calculate the radii (I think this is the easiest way to do this, if there is a simpler way, please feel free to let me know).
Here is how I plan on doing this:
1/ Use the y(t) function for every curve (p24 of this PDF)
2/ Evaluate it at every t
I should have the curvature for every x,y point, right? I'm worried about the 'scaling': t varies between 0 and 1 but x varies between way higher values (for example between 300 and 555). Isn't this going to make the calculation of the radius false?
Thank you very much in advance for your precious help,
Regards, LD
That formula is great when $y$ can be written as a function of $x$, but that doesn't work in cases where the assumption fails...for things like, say, an oval racetrack, where there are two $y$-values for every $x$-value, or for any more generic curve that might contain a vertical line segment (e.g., a Bezier!).
Instead, you want to use the parametric curvature formula: $$ k(t) = \frac{x''(t) y'(t) - y''(t)x'(t)} {(x'(t)^2 + y'(t)^2)^\frac{3}{2}} $$
(This formula assumes that the curve goes counterclockwise; if your curve goes clockwise, then you need to negate it.)
The radius of curvature is then $1/k(t)$.
The only problem arises when the denominator in $k$ is zero, which happens only when both the $x$ and $y$ derivatives are zero, i.e., when the curve is not "regular"; in this case, you get a $0/0$ form, and the formula's no good to you. In your project, it seems to me that this is unlikely to happen.
Of course, you're inverting $k$, so you'll have a problem if $$ x''(t) y'(t) - y''(t)x'(t) = 0 $$ at some time $t$; again, I expect this not to be a problem unless your racetrack has some long "straightaway," where the radius of curvature is infinite.
Here's a bit of sample code to show you what's going on.