c#积分法求取缓和曲线切线支距坐标,适用于大偏角切线支距坐标。
本帖最后由 flz0728 于 2023-12-16 10:56 编辑//定义被积函数
static double IntegrandCos(double l, double A)
{ return Math.Cos(Math.Pow(l, 2) / (2 * A * A)); }
static double IntegrandSin(double l, double A)
{ return Math.Sin(Math.Pow(l, 2) / (2 * A * A)); }
// 梯形法则进行数值积分
static double TrapezoidalRule(Func<double, double, double> integrand, double a, double b, int n, double A)
{
double h = (b - a) / n;
double sum = 0.5 * (integrand(a, A) + integrand(b, A));
for (int i = 1; i < n; i++)
{ sum += integrand(a + i * h, A); }
return sum * h;
}
/// <summary>
/// 使用高斯-克朗罗德法则进行积分计算切线支距坐标
/// </summary>
/// <param name="l">缓和曲线长度</param>
/// <param name="A">缓和曲线参数</param>
/// <param name="n">分割的数量,越大计算越精确但是计算量越大</param>
/// <param name="x">切线支距X坐标</param>
/// <param name="y">切线支距Y坐标</param>
public void QXZJZBjifenX(double l, double A, int n, out double x, out double y)
{
x = 0;
y = 0;
// 使用高斯-克朗罗德法则进行积分计算
x = TrapezoidalRule(IntegrandCos, 0, l, n, A);
y = TrapezoidalRule(IntegrandSin, 0, l, n, A);
}
/// <summary>
/// 根据缓和曲线长度和缓和曲线参数求缓和曲线的坐标增量
/// </summary>
/// <param name="l">缓和曲线长度</param>
/// <param name="A">缓和曲线参数</param>
/// <param name="X">X方向坐标增量</param>
/// <param name="Y">Y方向坐标增量</param>
public void Qzjzb(double l, double A, out double X, out double Y)
{
//X = l - Math.Pow(l, 5) / (40 * Math.Pow(A, 4)) + Math.Pow(l, 9) / (3456 * Math.Pow(A, 8)) - Math.Pow(l, 13) / (599040 * Math.Pow(A, 12));
// Y = Math.Pow(l, 3) / (6 * Math.Pow(A, 2)) - Math.Pow(l, 7) / (336 * Math.Pow(A, 6)) + Math.Pow(l, 11) / (42240 * Math.Pow(A, 10)) - Math.Pow(l, 15) / (9676800 * Math.Pow(A, 14));
QXZJZBjifenX(l, A, 10000, out X, out Y);
}
页:
[1]