interpolation - Numpy: find mean coordinate of points along line -


i have bunch of points in 2d space reside on line (polygon). how can compute mean coordinate of these points on line?

i don't mean centroid of points in 2d space (as @rth proposed in answer), mean location of points along line on reside. basically, transform line 1d axis, compute mean location in 1d, , transform location of mean 2d space.

maybe these necessary steps, think (or hope) there function in numpy/scipy allows me in 1 step.

edit: approach describe in question indeed simplest way solving problem.

here implementation calculates positions of vertices along line in 1d, takes mean, , calculates corresponding 2d position parametric interpolation,

import numpy np scipy.interpolate import splprep, splev  vert = np.random.randn(1000, 2) # vertices definition here  # calculate euclidean distances between consecutive vertices # equivalent loop # dl[i] = ((vert[i+1, 0] - vert[i, 0])**2 + (vert[i+1,1] - vert[i,1])**2)**0.5 dl = (np.diff(vert, axis=0)**2).sum(axis=1)**0.5   # pad 0, dl.shape[0] == vert.shape[0] convenience dl = np.insert(dl, 0, 0.0) l = np.cumsum(dl) # 1d coordinates along line l_mean = np.mean(l) # mean in line coordinates  # calculate coordinate of l_mean in 2d space # parametric b-spline interpolation tck, _ = splprep(x=vert.t,  u=l, k=3) res = splev(l_mean, tck) print(res) 

edit2: assuming have high resolution set of points path vert_full , approximate measurements vert_1, vert_2, etc, following.

  • project each points of vert_1, etc. onto exact path. assuming vert_full has more datapoints vert_1, can nearest neighbours of vert_1 in vert_full:

    from scipy.spatial import ckdtree tr = ckdtree(vert_full) d, idx = tr.query(vert_1, k=1) vert_1_proj = vert_full[idx] # gives projected corrdinates onto vert_full # have not run this, might require minor changes 
  • use above mean calculation new vert_1_proj vector.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -