简体   繁体   English

强制贝塞尔循环在边界内说

[英]Force bezier loop to say inside boundary

I'm writing a code to simulate a lap time on motorcycle, using GNU Octave.我正在使用 GNU Octave 编写代码来模拟摩托车的单圈时间。 The racetrack is represented by the mid line (as xy point values) and width "B".赛道由中线(作为 xy 点值)和宽度“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.赛道中线各点距离不等,例如直线段只有两个点,弯道可能有5-10个点。

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).我想计算贝塞尔曲线与中线的距离,以检查车辆是否偏离道路(如果距离 > B/2 我偏离轨道)。 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.作为替代方案,我尝试通过计算每个部分的角度来“拉直”中线,然后使用相同的“变换”拉直赛车线并检查最小和最大 Y 值,该值必须小于 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.另一种选择是将赛道转换为一个矩阵,其中赛道内填充“0”,赛道外填充“1”,并且赛车线将是一个具有相同 MxN 的矩阵,处处填充“0”,其他处填充“1”他赛车线。 By sum these two matrices, if there is some "2" I'm out of track.通过对这两个矩阵求和,如果有一些“2”我就跑偏了。 Right now I don't find a method to made this.现在我找不到制作这个的方法。

I've found the answer of my problem, using the function "inpolygon".我找到了我的问题的答案,使用 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. function 告诉我某个点是否在多边形之外。 Then, I repeat the same, setting inside boundary as polygon.然后,我重复相同的操作,将内部边界设置为多边形。 Now all racing line points must be outside the polygon.现在所有赛车线点都必须在多边形之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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