简体   繁体   中英

Force bezier loop to say inside boundary

I'm writing a code to simulate a lap time on motorcycle, using GNU Octave. The racetrack is represented by the mid line (as xy point values) and width "B".

The points of the racetrack midline are not at the same distance, for example a straight section have just two points, a bend could have 5-10 points.

The racing line is a closed loop cubic bezier.

I would like to calculate the distance of that bezier from the midline, to check if the vehicle goes off road (if distance > B/2 I'm out of track). I'm not interested in where this happens, only if happens. Right now to check if the code works, I've made this by calculating the distance of every point of the racing line to the midline as the height of a triangle, where the two base vertex are two points of the mid line and the top vertex is the point of the racing line. It works but I'm looking for an alternative method because this one is very slow.

As alternative I tought to "straighten" the mid line by calculating angle of each section, and then straighten the racing line with the same "transformation" and check min and max Y value, that must be less than B/2. The problem with this approach is that racing line and mid line are not the same length, in some part of racetrack racing line could be shorter, in other could be longer, so the transformation will not be linear.

Another option could be to transform the racetrack into a matrix filled with "0" inside track, "1" outside track, and the racing line will be a matrix with the same MxN filled with "0" everywhere and "1" where there is he racing line. By sum these two matrices, if there is some "2" I'm out of track. Right now I don't find a method to made this.

I've found the answer of my problem, using the function "inpolygon". So, I set the outside boundary of racetrack as polygon, and all points of racing line as points to check. The function tell me if some point is outside the polygon. Then, I repeat the same, setting inside boundary as polygon. Now all racing line points must be outside the polygon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM