gpt4 book ai didi

algorithm - cornu螺旋/样条的高速绘图算法?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:52:47 24 4
gpt4 key购买 nike

有没有人见过角形螺旋线(也称为回旋曲线)或样条曲线的合适绘图算法?对于圆弧和直线,我们有 Bresenham 算法之类的东西。这适用于回旋曲线吗?​​

维基百科页面有这个 Sage 代码:

p = integral(taylor(cos(L^2), L, 0, 12), L)
q = integral(taylor(sin(L^2), L, 0, 12), L)
r1 = parametric_plot([p, q], (L, 0, 1), color = 'red')

是否有可用的参数图示例代码?我的网络搜索结果不多。

最佳答案

我没有看到任何现有的高速算法。但是,我确实了解了绘制这种东西的常用方法。本质上,您递归地拆分 L,直到计算出的左、中和右点足够接近一条直线,您可以绘制该直线。我能够使用 MathNet.Numerics.dll 进行集成。一些代码:

    public static void DrawClothoidAtOrigin(List<Point> lineEndpoints, Point left, Point right, double a, double lengthToMidpoint, double offsetToMidpoint = 0.0)
{
// the start point and end point are passed in; calculate the midpoint
// then, if we're close enough to a straight line, add that line (aka, the right end point) to the list
// otherwise split left and right

var midpoint = new Point(a * C(lengthToMidpoint + offsetToMidpoint), a * S(lengthToMidpoint + offsetToMidpoint));
var nearest = NearestPointOnLine(left, right, midpoint, false);
if (Distance(midpoint, nearest) < 0.4)
{
lineEndpoints.Add(right);
return;
}
DrawClothoidAtOrigin(lineEndpoints, left, midpoint, a, lengthToMidpoint * 0.5, offsetToMidpoint);
DrawClothoidAtOrigin(lineEndpoints, midpoint, right, a, lengthToMidpoint * 0.5, offsetToMidpoint + lengthToMidpoint);
}

private static double Distance(Point a, Point b)
{
var x = a.X - b.X;
var y = a.Y - b.Y;
return Math.Sqrt(x * x + y * y);
}

private static readonly double PI_N2 = Math.Pow(Math.PI * 2.0, -0.5);

public static double C(double theta)
{
return Integrate.OnClosedInterval(d => Math.Cos(d) / Math.Sqrt(d), 0.0, theta) / PI_N2;
}

public static double S(double theta)
{
return Integrate.OnClosedInterval(d => Math.Sin(d) / Math.Sqrt(d), 0.0, theta) / PI_N2;
}

关于algorithm - cornu螺旋/样条的高速绘图算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11211655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com