Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance along poly line/Spline #252

Closed
banesullivan opened this issue Jun 11, 2019 · 5 comments
Closed

Distance along poly line/Spline #252

banesullivan opened this issue Jun 11, 2019 · 5 comments
Labels
feature-request Please add this cool feature!

Comments

@banesullivan
Copy link
Member

banesullivan commented Jun 11, 2019

Could we add a way to compute the distance along every node/point in a poly line when creating them via pyvista.Spline? pinging @akaszynski

Note that I added this for straight lines from pyvista.Line in #250:

line = pyvista.wrap(src.GetOutput())
# Compute distance of every point along line
compute = lambda p0, p1: np.sqrt(np.sum((p1 - p0)**2, axis=1))
distance = compute(np.array(pointa), line.points)
line['Distance'] = distance
return line

However this only works for computing distances along straight lines. How would we go about computing the distances of points along a ploy line? And once we figure this out, let's add a 'Distance' array to the pyvista.Spline output by default.

@banesullivan banesullivan added the feature-request Please add this cool feature! label Jun 11, 2019
@banesullivan
Copy link
Member Author

Perhaps we could just use the vtkImplicitPolyDataDistance class?...

@akaszynski
Copy link
Member

vtkImplicitPolyDataDistance might not work on coarse splines as it computes the distance to the nearest point, which might not be the "next" point on a line. From what I've seen online for VTK, there's nothing that computes the distance along the spline. One workaround would be to generate a very dense interpolation and then compute the distance along that line:

spline = pv.Spline(points, 1000)

dense_spline = pv.Spline(points, 10000)
inc_dist = (np.diff(dense_spline.points, axis=0)**2).sum(1)
dist = np.cumsum(inc_dist)

spline['distance'] = dist[::10]

# tube = spline.tube(radius=0.1)
tube = spline.tube(radius=0.1)
tube.plot(scalars='distance', smooth_shading=True)

@banesullivan
Copy link
Member Author

I just found out the poly lines/splines are actually linearly segmented. Which means any distance computed along the line would be a sum of Euclidean distances between points along the line.

This is pretty easy to implement so I'll just do a cumulative summation of the distances between the nodes

@banesullivan
Copy link
Member Author

Actually, the filter vtkAppendArcLength is meant for exactly this task which I implemented under PolyData.compute_arc_length

@AlexanderJuestel
Copy link

@banesullivan maybe just an addition to this issue: Is there a way to retrieve the XYZ position of a point along this line given a distance? The point is most like not located on a vertex/note but rather located along a linear segment.

I am particularly interested in that since we can display wells/boreholes including their deviation in PyVista (see image). We then know the stratigraphic boundaries in a given measured depth (along the spline) and would like to get the TVD (true vertical depth) of the point for subsequent structural modeling for instance in GemPy. So that you can combine the representations of the GemPy/Pyvista meshes with the boreholes.

I am also happy to open a new issue or discussion on that :)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Please add this cool feature!
Projects
None yet
Development

No branches or pull requests

3 participants