开发者

Average 3D paths

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 x开发者_运维知识库yz pairs).

Any help would be appreciated.


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.


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


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)>.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜