[Python |
您所在的位置:网站首页 › 数学美丽曲线怎么画 › [Python |
文章目录
前言直角坐标系表达python代码实现总结应用
前言
Clothoid曲线是一种曲率随着弧长线性变化的曲线。在直线段与其它曲线轨迹过渡的阶段采用这类曲线可以起到平滑曲率的作用。在车辆行驶轨迹设计中,如果使用这类曲线,可以减少曲率突变对转向控制的要求,降低控制难度,改善控制效果。这篇文章主要用于工程应用,而非理论推导。 直角坐标系表达Clothoid曲线的数学表达式如下,其中a为常数,l为曲线长度, k为曲率;
但在实际应用中,发现上述思路还存在一定的约束,即给定初始曲率和终止曲率后,曲线的长度并不是给定任意值就可以的: 1、首先, 上面计算标准坐标系下曲线的点坐标采用的是无穷计算展开进行计算,在实际的计算机上面是不可能实现的,因此就必须近似求解,也就是对上面的迭代次数n选取,n太大计算太慢,太小精度不够 2、观察这个无穷技术,其中最高阶次项为弧长l的4n+3次方,对于python来说,最大的浮点数阶次为300左右,因此有: 计算非标准坐标系下的坐标点 def clothoid(curveStart, curveEnd, curveLength, distance):#curveLength为截取曲线的长度,distance为相对于截取段起始点s0处的距离,给定一个distance就返回该distance处的XY坐标 A = (curveEnd - curveStart) / curveLength s0 = curveStart / A X0, Y0 = clothoidcooridnate(A, s0) heading0 = A / 2 * s0 ** 2 transferMatrix = np.linalg.inv(transfercoordinate(heading0)) X, Y = clothoidcooridnate(A, distance + s0) local = np.dot(transferMatrix, np.array([[X], [Y]]) - np.array([[X0], [Y0]])) x = local[0, 0] y = local[1, 0] heading = A / 2 * distance ** 2 + curveStart * distance return x, y, heading, math.cos(heading), math.sin(heading)计算标准坐标系下的坐标点 def clothoidcooridnate(A: float, distance: float): x = 0.0 y = 0.0 for n in range(30): x += math.pow(-1, n) * math.pow(A, 2 * n) * math.pow(distance, 4 * n + 1) / \ (math.factorial(2 * n) * (4 * n + 1) * math.pow(2, 2 * n)) y += math.pow(-1, n) * math.pow(A, 2 * n + 1) * math.pow(distance, 4 * n + 3) / \ (math.factorial(2 * n + 1) * (4 * n + 3) * math.pow(2, 2 * n + 1)) return x, y坐标转换矩阵 def transfercoordinate(heading: float = 0.0) -> np.ndarray: return np.array([[math.cos(heading), -math.sin(heading)], [math.sin(heading), math.cos(heading)]])主程序 if __name__=="__main__": curStart = 0.4#截取曲线起点曲率 curEnd = 0.5##截取曲线终点曲率 n = 30#设置的迭代步长30 l2 = 4*n + 1 l3= math.pow(10, 300/(4*n+1)) lk0 = min(2* math.pow(math.factorial(2*n), 1 / (2*n))/abs(curStart + 1e-5), l2, l3) lkt = min(2*math.pow(math.factorial(2*n), 1 / (2*n))/abs(curEnd + 1e-5), l2, l3) '''允许设置的曲线长度''' allowsCurveLength = abs(lk0+lkt) if curEnd*curStart |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |