平均 3D 路径

发布于 2024-12-05 07:54:26 字数 333 浏览 0 评论 0原文

我有两条 3D 路径,如果有的话,我想对它们进行“平均”。

我在采样时对 xyz 对进行了时间戳:

    ms   x   y   z
    3   0.1 0.2 0.6
    12  0.1 0.2 1.3
    23  2.1 4.2 0.3
    55  0.1 6.2 0.3

有关路径的事实:

  • 它们都在同一 xyz 点/附近开始和结束。
  • 我有完成路径所需的总持续时间以及各个顶点,
  • 它们具有不同的长度(即不同数量的 xyz 对)。

任何帮助将不胜感激。

I have two paths in 3D and I want to "average" them, if there's such a thing.

I have the xyz pairs timestamped at the time they were sampled:

    ms   x   y   z
    3   0.1 0.2 0.6
    12  0.1 0.2 1.3
    23  2.1 4.2 0.3
    55  0.1 6.2 0.3

Facts about the paths:

  • They all start and end on/near the same xyz point.
  • I have the total duration it took to complete the path as well as individual vertices
  • They have different lengths (i.e. different number of xyz pairs).

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

想念有你 2024-12-12 07:54:26

一个简单的方法如下...

首先构建一个函数 interp(t, T, waypoints) ,给定当前时间 t、总路径持续时间 T 路径 waypoints 返回当前位置。这可以使用线性插值或更复杂的方法来完成,以避免速度或加速度不连续。

一旦你有了interp,平均路径可以定义为(Python 中的示例)

def avg(t, T1, waypoints1, T2, waypoints2):
    T = (T1 + T2) / 2
    return middlePoint(interp(t*T1/T, T1, waypoints1),
                       interp(t*T2/T, T2, waypoints2))

平均路径的持续时间将是平均T = (T1 + T2) / 2两个持续时间。

更改此方法以创建加权平均路径也很容易。

A simple method is the following...

First build a function interp(t, T, waypoints) that given the current time t, the total path duration T and the path waypoints returns the current position. This can be done using linear interpolation or more sophisticated approaches to avoid speed or acceleration discontinuities.

Once you have interp the average path can be defined as (example in python)

def avg(t, T1, waypoints1, T2, waypoints2):
    T = (T1 + T2) / 2
    return middlePoint(interp(t*T1/T, T1, waypoints1),
                       interp(t*T2/T, T2, waypoints2))

the duration of the average path will be the average T = (T1 + T2) / 2 of the two durations.

It's also easy to change this approach to make a weighted average path.

兲鉂ぱ嘚淚 2024-12-12 07:54:26

在 R 中,该系列中连续点之间的距离(假设它位于名为“dat”的数据帧中)
可以是:

 with(dat, sqrt(diff(x)^2 +diff(y)^2 +diff(z)^2) )
#[1] 0.700000 4.582576 2.828427

我可以想到几个平均值,即间隔内的平均距离、单位时间行驶的平均距离。取决于你想要什么。这给出了三个区间的平均速度:

 with(dat, sqrt(diff(x)^2 +diff(y)^2 +diff(z)^2) /diff(ms) )
#[1] 0.07777778 0.41659779 0.08838835

In R, the distances between consecutive points in that series assuming it is in a dataframe named "dat"
would be:

 with(dat, sqrt(diff(x)^2 +diff(y)^2 +diff(z)^2) )
#[1] 0.700000 4.582576 2.828427

There are a couple of averages I could think of average distance in interval, average distance traveled per unit time. Depends on what you want. This gives the average velocity in the three intervals:

 with(dat, sqrt(diff(x)^2 +diff(y)^2 +diff(z)^2) /diff(ms) )
#[1] 0.07777778 0.41659779 0.08838835
执妄 2024-12-12 07:54:26

肯定有这样的事情。对于路径 A 上的每个点,找到与路径 B 上的当前点对应的点,然后找到这些对应顶点之间的中点。然后,您将得到两条路径之间的一条路径,即两条路径的“平均值”。如果您没有对两条路径进行相同的采样而出现不匹配,则对于路径 A 上的内部点(即不是终点),找到路径上具有相似时间采样的两个最接近的采样点B,找到这三个点将形成的三角形的中点。

现在,由于您已经通过采样对路径进行了离散化,因此这个“平均值”只是一个近似值,而不是“真实”平均值,就像您可以通过求解 定义的两个可微参数函数之间的平均函数来实现的那样r(t) =

There is definitely such a thing. For each point on path A, find the point that correponds to your current point on path B, and then find the mid-point between those corresponding verticies. You will then get a path in-between the two that is the "average" of the two paths. If you have a mis-match where you did not sample the two paths the same, then for an interior point on path A (i.e., not the end-point), find the two closest sampled points with a similar time-sampling on path B, and locate the mid-point of the triangle those three points will make.

Now since you've discreetized your path by sampling it, this "average" is only going to be an approximation, not a "true" average like you could do by solving for the average function between two differentiable parametric functions defined by r(t) = <x(t), y(t), z(t)>.

淤浪 2024-12-12 07:54:26

扩展@6502的答案。

如果您希望检索构成平均路径的点列表,您可以在各个输入点的实例处对 avg 函数进行采样。 (向平均长度拉伸)

def avg2(T1, waypoints1, T2, waypoints2):
    # Collect the times we want to sample at
    T = (T1 + T2) / 2
    times = []
    times.extend(t*T/T1 for (t,x,y) in waypoints1)  # Shift the time towards
    times.extend(t*T/T2 for (t,x,y) in waypoints2)  #   the average
    times.sort()

    result = []
    last_t = None
    for t in times:
        # Check if we have two points in close succession
        if last_t is not None and last_t + 1.0e-6 >= t:
            continue
        last_t = t

        # Sample the average path at this instance
        x, y = avg(t, T1, waypoints1, T2, waypoints2)
        yield t, x, y

Expanding on @6502's answer.

If you wish to retrieve a list of points that would make up the average path, you could sample the avg function at the instances of the individual input points. (Stretched toward the average length)

def avg2(T1, waypoints1, T2, waypoints2):
    # Collect the times we want to sample at
    T = (T1 + T2) / 2
    times = []
    times.extend(t*T/T1 for (t,x,y) in waypoints1)  # Shift the time towards
    times.extend(t*T/T2 for (t,x,y) in waypoints2)  #   the average
    times.sort()

    result = []
    last_t = None
    for t in times:
        # Check if we have two points in close succession
        if last_t is not None and last_t + 1.0e-6 >= t:
            continue
        last_t = t

        # Sample the average path at this instance
        x, y = avg(t, T1, waypoints1, T2, waypoints2)
        yield t, x, y
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文