Consider the following photo:
To magnify image, right click and select open-image in new tab or something similar

The photo above is a random race circuit data I've collected. What I'm trying to do is find the corner entry, and corner exit. The path in the middle would be known as sector. The corner entry and exits are labelled in green in the following image,

(Note where they are position in the road is the job of my AI algorithm thus for this, we are placing these entry and exit points in the middle). The following are the observations I made for the entry/exist points:
- entry have close to zero slope and then a change of slope.
- exit have changing slopes before it until a point with zero slopes is hit.
- For corners with "S" like formation, the inflection point is both an entry/exit point.
Also we are ignoring z-axis.
My plan so far is the following:
- take the first derivative of each point via parametric derivative, $\dfrac{dy}{dx} = \dfrac{\dfrac{dy}{dt}}{\dfrac{dx}{dt}}$.
- From (1), I will take the vertices that have the last 0 slope prior to change of slope (indicating corner entry).
- From (1), I will take the vertices that is the first 0 slope after a sequence of non-zero slope, indicating corner exit.
(Note that the first derivative also takes in inflection points, since inflection points have 0 slope).
Problem:
My plan seems to not work and places corner exit and entry in wrong places (e.g. lump in straight aways). Considering that corner entry often have gentle slopes, this sometimes doesn't place the entry point until we are deep in the corner (which is bad). I've been debugging this problem for quite a while so before I go on I have two main questions:
- If my idea is right (or close to right), could it be that my implementation is wrong?
- If you have a better method of finding corner sectors, can you share it with me?
Edit:
I thank both answers. My level is too low to thumbs up so I have to use prng to select one answer. Anyway, the program is working perfectly. The following is the line graph generated by curvature along the circuit:

Basically, the local minimums corresponds to straight-away. It even captures the big irregular hairpin with smaller straight away. One could even incorporate filtering to avoid the noise. Again, I thank all of the answers.
I think a useful quantity for you would be there curvature of your racetrack, which measures how sharp you are turning. If you a parameterization $x(t),y(t)$ of your racetrack, the curvature at the point $(x(t),y(t))$ is $$ \kappa(t)=\frac{x'y''-x''y'}{(x'^2+y'^2)^{3/2}} $$ Note this can be negative. I believe positive curvature means you're turning left, negative right.
Then, to find the entry/exit points, choose some value $\kappa_0$, and let the entry points be the points $(x(t),y(t))$ where $|\kappa(t)|$ goes from being beneath $\kappa_0$ to above it, and the exit points the opposite, where $|\kappa(t)|$ is above $\kappa_0$, and dips below. The idea is that the regions between entry and exit points will be regions of high (specifically, $>\kappa_0$) curvature. Playing with the value of $\kappa_0$ should give you what you want.