In theory, linear interpolation can be done with any triangulation (not just a Delaunay triangulation).
I am trying to use scipy.interpolate.LinearNDInterpolator with a pre-computed 3D triangulation which is not of class scipy.spatial.Delaunay. However, this won't work because the SciPy code checks the class of the triangulation (if isinstance(points, qhull.Delaunay)...). I tried to create a 'fake' Delaunay triangulation with the correct class by changing the 'points' and 'simplices' attributes of a Delaunay object, but I received the error AttributeError: can't set attribute.
Is there a way around this, or another library for linear interpolation?
It looks like matplotlib.tri.LinearTriInterpolator might be a good alternative. I will update this post when I have tested this.
Edit: This is not a solution to my problem because it is only implemented in 2-D.
Related
Objective
Display a 3D Sphere graph structure based on input edges & nodes using VTK for visualisation. As for example shown in https://epfl-lts2.github.io/gspbox-html/doc/graphs/gsp_sphere.html
Target:
State of work
Input data as given factor
NetworkX for position calculation
Handover to VTK methods for 3D visualisation
Problem
3 years ago, I had achieved the visualisation as shown above. Unfortunately, I did a little bit of too much cleaning and I just realized, that I dont have these methods anymore. It is somehow a force-directed graph on a sphere surface. Maybe similar to the "strong gravity" parameter in the 2D forceatlas. I have not found any 3D implementation of this yet.
I tried again with the following algorithms, but none of them has produced this layout, neither have parameter tuning of these algorithms (or did I miss an important one?):
NetworkX: Spherical, Spring, Shell, Kamada Kawaii, Fruchterman-Reingold (the 2D fruchterman-reingold in Gephi looks like it could come close to the target in a 3D version, yet gephi does not support 3D or did I oversee something?)
ForceAtlas2
Gephi (the 2D fruchterman-reingold looks like a circle, but this is not available in 3D, nor does the 3D Force Atlas produce valid Z-Coordinates (they are within a range of +1e-4 and -1e-4)
Researching for "spherical graph layout" has not brought me to any progress (only to this view which seems very similar https://observablehq.com/#fil/3d-graph-on-sphere ).
How can I achieve this spherical layout using python (or a third party which provides a positioning information)
Update: I made some progress and found the keywords non-euclidean, hyperbolic and spherical force-directed algorithms, however still not achieved anything yet. Or Non-Euclidean Riemann Embeddings (https://www2.cs.arizona.edu/~kobourov/riemann_embedders.pdf)
Have you tried the python lib version of the GSPBOX?
If yes, why it does not work for you?
https://pygsp.readthedocs.io/en/stable/reference/graphs.html
I've implemented the Sibon/natural neighbor spatial interpolation using scipy's Voronoi and Shapely's polygons.
But I need to restrict my voronoi diagram as there are some polygons that are unrealistically extended way out of the domain I'm interpolating in which causes inaccuracies. Also there are non-finite regions in the Voronoi diagram for the outer points which I'd rather not have.
I often see that the Voronoi diagram is bounded in a rectangular box but I don't know how to implement it. I have tried to look for it in the scipy documentation without success.
Edit: found how to do it thanks to this post:Colorize Voronoi Diagram
Thanks to anyone that took the time to read and/or write.
I am using the Scipy CubicSpline interpolation based on a certain number of points as shown in the diagram below:
My problem is, the second derivative of the Cubic Splive function looks a little bit edgy:
In order to smooth the second curve I need a higher degree of spline interpolation. Is there a Scipy build in function (similar to CubicSpline) or an easy way to do that? (A b-spline function want work)
make_interp_spline should be able to construct BSpline objects of higher degrees (FITPACK only goes up to k=5, which is hardcoded fairly deep down).
I'm trying create a triangular mesh using python.
As I know the boundary points, I think the delaunay method is more appropriated.
I tried use scipy. the code is very simple
from scipy.spatial import Delaunay
pixelpoints = np.transpose(np.nonzero(binaryImage))
tri = Delaunay(pixelpoints)
import matplotlib.pyplot as plt
plt.triplot(pixelpoints[:,0], pixelpoints[:,1], tri.simplices.copy())
plt.plot(pixelpoints[:,0], pixelpoints[:,1], 'o')
plt.show()
But I don't want this. I'd like to mesh inside the image bounds. Also, I don't want to mesh inside the holes.
Can I control the number of triangles to cover a surface?
Is there an alternative way to do this?
Thank you.
You can easily remove additional triangles using the Polygon.IsPointInside(tCentroid) where tCentroid is the triangle centroid. IsPointInside() can be derived by this: http://geomalgorithms.com/a03-_inclusion.html.
The Triangle program supports both these needs: refining triangles to a prescribed size and removing triangles outside the polygon or in holes. There seems to be a python interface floating around: the API describes how to specify holes and a maximum triangle area.
Having a cloud point shaped like some sort of distorted paraboloid, I would like to use Delaunay Triangulation to interpolate the points. I have tried other techniques (f.ex. splines) but did not manage to enforce the desired behavior.
I was wondering if there's a quick way to use the results of scipy.spatial.Delaunay in a way where I can give the (x,y) coords and get the z-coord of the point on the simplex (triangle).
From the documentation looks like I can pull out the index of the simplex but I am not sure how to take it from there.
You can give the Delaunay triangulation to scipy.interpolate.LinearNDInterpolator together with the set of Z-values, and it should do the job for you.
If you really want to do the interpolation yourself, you can build it up from find_simplex and transform.