CARLA
 
载入中...
搜索中...
未找到
odrSpiral.cpp
浏览该文件的文档.
1/* ===================================================
2 * 文件名:odrSpiral.c
3 * ---------------------------------------------------
4 * 目的:用于计算OpenDRIVE应用程序中螺旋线的免费方法
5 * ---------------------------------------------------
6 * 使用CEPHES库的方法。
7 * ---------------------------------------------------
8 * first edit: 09.03.2010 by M. Dupuis @ VIRES GmbH
9 * last mod.: 09.03.2010 by M. Dupuis @ VIRES GmbH
10 * ===================================================
11 Copyright 2010 VIRES Simulationstechnologie GmbH
12
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
16
17 http://www.apache.org/licenses/LICENSE-2.0
18
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24
25
26 NOTE:
27 The methods have been realized using the CEPHES library
28
29 http://www.netlib.org/cephes/
30
31 and do neither constitute the only nor the exclusive way of implementing
32 spirals for OpenDRIVE applications. Their sole purpose is to facilitate
33 the interpretation of OpenDRIVE spiral data.
34 */
35
36/* ====== 头文件包含 ====== */
37#include <stdio.h>
38// 对原文件的编辑-----
39#define _USE_MATH_DEFINES // 启用与Windows的兼容性
40// --------------------------
41#include <math.h>
42
43/* ====== 局部变量 ======*/
44
45/* 小 x 值对应的 S(x)*/
46// 定义一个静态双精度数组sn,用于存储特定的数值,这些数值可能会在后续计算S(x)(小x值情况)时用到
47static double sn[6] = {
48-2.99181919401019853726E3,
49 7.08840045257738576863E5,
50-6.29741486205862506537E7,
51 2.54890880573376359104E9,
52-4.42979518059697779103E10,
53 3.18016297876567817986E11,
54};
55// 定义一个静态双精度数组sd,同样用于后续相关计算(可能是配合sn一起用于S(x)的计算等)
56static double sd[6] = {
57/* 1.00000000000000000000E0,*/
58 2.81376268889994315696E2,
59 4.55847810806532581675E4,
60 5.17343888770096400730E6,
61 4.19320245898111231129E8,
62 2.24411795645340920940E10,
63 6.07366389490084639049E11,
64};
65
66/* C(x) for small x */
67static double cn[6] = {
68-4.98843114573573548651E-8,
69 9.50428062829859605134E-6,
70-6.45191435683965050962E-4,
71 1.88843319396703850064E-2,
72-2.05525900955013891793E-1,
73 9.99999999999999998822E-1,
74};
75static double cd[7] = {
76 3.99982968972495980367E-12,
77 9.15439215774657478799E-10,
78 1.25001862479598821474E-7,
79 1.22262789024179030997E-5,
80 8.68029542941784300606E-4,
81 4.12142090722199792936E-2,
82 1.00000000000000000118E0,
83};
84
85/* Auxiliary function f(x) */
86static double fn[10] = {
87 4.21543555043677546506E-1,
88 1.43407919780758885261E-1,
89 1.15220955073585758835E-2,
90 3.45017939782574027900E-4,
91 4.63613749287867322088E-6,
92 3.05568983790257605827E-8,
93 1.02304514164907233465E-10,
94 1.72010743268161828879E-13,
95 1.34283276233062758925E-16,
96 3.76329711269987889006E-20,
97};
98static double fd[10] = {
99/* 1.00000000000000000000E0,*/
100 7.51586398353378947175E-1,
101 1.16888925859191382142E-1,
102 6.44051526508858611005E-3,
103 1.55934409164153020873E-4,
104 1.84627567348930545870E-6,
105 1.12699224763999035261E-8,
106 3.60140029589371370404E-11,
107 5.88754533621578410010E-14,
108 4.52001434074129701496E-17,
109 1.25443237090011264384E-20,
110};
111
112/* Auxiliary function g(x) */
113static double gn[11] = {
114 5.04442073643383265887E-1,
115 1.97102833525523411709E-1,
116 1.87648584092575249293E-2,
117 6.84079380915393090172E-4,
118 1.15138826111884280931E-5,
119 9.82852443688422223854E-8,
120 4.45344415861750144738E-10,
121 1.08268041139020870318E-12,
122 1.37555460633261799868E-15,
123 8.36354435630677421531E-19,
124 1.86958710162783235106E-22,
125};
126static double gd[11] = {
127/* 1.00000000000000000000E0,*/
128 1.47495759925128324529E0,
129 3.37748989120019970451E-1,
130 2.53603741420338795122E-2,
131 8.14679107184306179049E-4,
132 1.27545075667729118702E-5,
133 1.04314589657571990585E-7,
134 4.60680728146520428211E-10,
135 1.10273215066240270757E-12,
136 1.38796531259578871258E-15,
137 8.39158816283118707363E-19,
138 1.86958710162783236342E-22,
139};
140
141//polevl 函数
142//计算多项式值的函数
143static double polevl( double x, double* coef, int n )
144{
145 double ans;
146 double *p = coef;
147 int i;
148
149 ans = *p++;
150 i = n;
151
152 do
153 {
154 ans = ans * x + *p++;
155 }
156 while (--i);
157
158 return ans;
159}
160//p1evl 函数
161//计算1开始的多项式值的函数,即多项式第一项为x
162//参数与返回值与polevl函数相同
163static double p1evl( double x, double* coef, int n )
164{
165 double ans;
166 double *p = coef;
167 int i;
168
169 ans = x + *p++;
170 i = n - 1;
171
172 do
173 {
174 ans = ans * x + *p++;
175 }
176 while (--i);
177
178 return ans;
179}
180
181//fresnel 函数
182//计算Fresnel积分的函数
183static void fresnel( double xxa, double *ssa, double *cca )
184{
185 double f, g, cc, ss, c, s, t, u;
186 double x, x2;
187
188 x = fabs( xxa );
189 x2 = x * x;
190
191 if ( x2 < 2.5625 )
192 {
193 t = x2 * x2;
194 ss = x * x2 * polevl (t, sn, 5) / p1evl (t, sd, 6);
195 cc = x * polevl (t, cn, 5) / polevl (t, cd, 6);
196 }
197 else if ( x > 36974.0 )
198 {
199 cc = 0.5;
200 ss = 0.5;
201 }
202 else
203 {
204 x2 = x * x;
205 t = M_PI * x2;
206 u = 1.0 / (t * t);
207 t = 1.0 / t;
208 f = 1.0 - u * polevl (u, fn, 9) / p1evl(u, fd, 10);
209 g = t * polevl (u, gn, 10) / p1evl (u, gd, 11);
210
211 t = M_PI * 0.5 * x2;
212 c = cos (t);
213 s = sin (t);
214 t = M_PI * x;
215 cc = 0.5 + (f * s - g * c) / t;
216 ss = 0.5 - (f * c + g * s) / t;
217 }
218// 根据xxa的符号调整cc和ss的符号
219 if ( xxa < 0.0 )
220 {
221 cc = -cc;
222 ss = -ss;
223 }
224
225 *cca = cc;
226 *ssa = ss;
227}
228
229
230/**
231* compute the actual "standard" spiral, starting with curvature 0
232* @param s run-length along spiral
233* @param cDot first derivative of curvature [1/m2]
234* @param x resulting x-coordinate in spirals local co-ordinate system [m]
235* @param y resulting y-coordinate in spirals local co-ordinate system [m]
236* @param t tangent direction at s [rad]
237*/
238
239//计算螺旋线参数的主要函数
240void odrSpiral( double s, double cDot, double *x, double *y, double *t )
241{
242 double a;
243
244 a = 1.0 / sqrt( fabs( cDot ) );
245 a *= sqrt( M_PI );
246
247 // 计算Fresnel积分,得到螺旋线的x和y坐标(经过缩放)
248 fresnel( s / a, y, x );
249
250 // 应用缩放因子a到x和y坐标上
251 *x *= a;
252 *y *= a;
253
254 // 如果cDot小于0,则反转y轴的方向
255 if ( cDot < 0.0 )
256 *y *= -1.0;
257
258 *t = s * s * cDot * 0.5;
259}
包含客户端相关类和定义的命名空间。
Definition AtomicList.h:17
static double sn[6]
Definition odrSpiral.cpp:47
static double gn[11]
static double fd[10]
Definition odrSpiral.cpp:98
static double p1evl(double x, double *coef, int n)
static double cd[7]
Definition odrSpiral.cpp:75
static double sd[6]
Definition odrSpiral.cpp:56
static double cn[6]
Definition odrSpiral.cpp:67
static void fresnel(double xxa, double *ssa, double *cca)
static double fn[10]
Definition odrSpiral.cpp:86
void odrSpiral(double s, double cDot, double *x, double *y, double *t)
compute the actual "standard" spiral, starting with curvature 0
static double polevl(double x, double *coef, int n)
static double gd[11]