How interpolate 3D coordinates - python

I have data points in x,y,z format. They form a point cloud of a closed manifold. How can I interpolate them using R-Project or Python? (Like polynomial splines)

It depends on what the points originally represented. Just having an array of points is generally not enough to derive the original manifold from. You need to know which points go together.
The most common low-level boundary representation ("brep") is a bunch of triangles. This is e.g. what OpenGL and Directx get as input. I've written a Python software that can convert triangular meshes in STL format to e.g. a PDF image. Maybe you can adapt that to for your purpose. Interpolating a triangle is usually not necessary, but rather trivail to do. Create three new points each halfway between two original point. These three points form an inner triangle, and the rest of the surface forms three triangles. So with this you have transformed one triangle into four triangles.
If the points are control points for spline surface patches (like NURBS, or Bézier surfaces), you have to know which points together form a patch. Since these are parametric surfaces, once you know the control points, all the points on the surface can be determined. Below is the function for a Bézier surface. The parameters u and v are the the parametric coordinates of the surface. They run from 0 to 1 along two adjecent edges of the patch. The control points are k_ij.
The B functions are weight functions for each control point;
Suppose you want to approximate a Bézier surface by a grid of 10x10 points. To do that you have to evaluate the function p for u and v running from 0 to 1 in 10 steps (generating the steps is easily done with numpy.linspace).
For each (u,v) pair, p returns a 3D point.
If you want to visualise these points, you could use mplot3d from matplotlib.

By "compact manifold" do you mean a lower dimensional function like a trajectory or a surface that is embedded in 3d? You have several alternatives for the surface-problem in R depending on how "parametric" or "non-parametric" you want to be. Regression splines of various sorts could be applied within the framework of estimating mean f(x,y) and if these values were "tightly" spaced you may get a relatively accurate and simple summary estimate. There are several non-parametric methods such as found in packages 'locfit', 'akima' and 'mgcv'. (I'm not really sure how I would go about statistically estimating a 1-d manifold in 3-space.)
Edit: But if I did want to see a 3D distribution and get an idea of whether is was a parametric curve or trajectory, I would reach for package:rgl and just plot it in a rotatable 3D frame.
If you are instead trying to form the convex hull (for which the word interpolate is probably the wrong choice), then I know there are 2-d solutions and suspect that searching would find 3-d solutions as well. Constructing the right search strategy will depend on specifics whose absence the 2 comments so far reflects. I'm speculating that attempting to model lower and higher order statistics like the 1st and 99th percentile as a function of (x,y) could be attempted if you wanted to use a regression effort to create boundaries. There is a quantile regression package, 'rq' by Roger Koenker that is well supported.

Related

How do you find the coordinates of a plane with a minimized distance strictly above a 3D dataset (python)?

As the title states, I need to make a plane above a 3D dataset in Python. There should be no data points above such plane, and the distances between the plane and the dataset should be optimized such that the plane somehow generalizes the whole data.
this is the 3d surface plot
(this is another example) the plane should look like this
I've been stuck for months on how to start/approach this problem. Should I start looking for the maximums in the data? Should I start on finding the peak in the middle and tamper around the possible slopes of the plane? Or are there other appropriate mathematical methods for this?
Thanks ahead.

Evenly distributed points on spline using numpy

I'm using numpy to generate a spline based on b-spline parameters. These parameters have been read from a STEP file exported from CAD with the end goal being to write a 2D unstructured mesh generator. I need to generate evenly spaced points on the spline to act as vertexes for the mesh elements.
Annoyingly, however, numpy is generating highly unevenly distributed points along the spline and I'm not sure why.
Here is an example of an aerofoil b-spline - the control points are relatively evenly placed around the spline and there is sufficient resolution in the spline coordinates.
But when I evaluate the same spline with 10x less points, you can see the distribution is heavily weighted to the upper line.
This is the code I'm using to generate the points (the bspline parameters have already been defined according to the STEP file):
N=int(ctrl_pts.shape[0]*100) # number of points to evaluate
spline_range=np.linspace(
knot_vector[0],
knot_vector[-1],
N
)
bspline=numpy.interpolate.BSpline(knot_vector,ctrl_pts,degree)
points=bspline(spline_range)
Is there a way to 'redistribute' the points on the spline?

Is it an orthogonal projection in the Nearside Perspective?

I'm currently working on world map visualizations. For now, I can use a home-made software for visualizations and point projections (Java), but I would like to upgrade the soft to be able to use a similar tool in Python.
Thus, I wanted to use cartopy with the module PROJ4, not to re-code everything, and use the wonderfull existing libraries.
It perfectly works for the PlateCarree projection, but when I want to use the Nearside Perspective, I observe a small difference between the two methods.
The two following pictures are extracted from the Java software (1) and the cartopy plot (2).
Cartopy (0.17) is used with matplotlib (3.0.2) and proj4 (4.9.1). In both pictures, we are observing at lon=lat=0° and at 400 km.
Here is the first image (Java):
Java visualization
Here is the second one (Cartopy):
Cartopy representation
As one can observe, lands are over-represented in the cartopy plot. Asuming that I want to get exactly the same projection as the one in my Java software (same representation as the "TrueView angles" in Telecom fields), I discovered in the cartopy crs module:
class NearsidePerspective(_Satellite):
"""
Perspective view looking directly down from above a point on the globe.
In this projection, the projected coordinates are x and y measured from
the origin of a plane tangent to the Earth directly below the perspective
point (e.g. a satellite).
"""
So I got this question: which projection is this about? Are the angles kept, which would means that I have an undetected problem? Or is it an orthogonal projection on the tangent plane? In this case, angles are not conserved, and I would need a solution to apply another projection (the correct one in my case). I might use the wrong one...
Thanks for your time,
Lou
I'm not sure if it's an orthogonal projection, but what CartoPy is using is directly from Proj4:
https://proj4.org/operations/projections/nsper.html
I think coordinates in this Nearside Perspective coordinates are Cartesian distances (distances from the origin on a plane), not angles. It sounds like angles are what's being used for your projection. Have you looked at using the Geostationary projection, but with a different satellite height?
https://scitools.org.uk/cartopy/docs/latest/crs/projections.html#geostationary
I can say that in this projection, the coordinates are angles (multiplied by the satellite height). Might be what you're looking for.

How to plot the orientation of a rigid body on 2D plot

I am working on numerically integrating (with Euler method currently, but I plan to upgrade to Runge-Kutta in the future) a fourth order 3-dimensional system of differential equations in Python. The system has two spatial variables (x and y) and 1 rotational coordinate (theta), to display the orientation of the rigid body the system describes.
I was able to integrate the system just fine, and used matplotlib to generate plots of the x-coordinate versus the y-coordinate. This is a sample of the plot generated:
However, I would like to have a plot more like this:
Taken from Formation tracking control for multiple rigid bodies on matrix Lie
groups: A system decomposition approach by J. Sun and Z. Geng.
Here, they acheived a 2D plot of x vs. y, but also managed to show the orientation of the object at each instance along the trajectory. Does anyone know I could accomplish this with matplotlib?

How to use interpolation to calculate a force based on angle

I am trying to make a python script that will output a force based on a measured angle. The inputs are time, the curve and the angle, but I am having trouble using interpolation to fit the force to the curve. I looked at scipy.interpolate, but I'm not sure it will help me because the points aren't evenly spaced.
numpy.interp does not require your points to be evenly distributed. I'm not certain if you mean by "The inputs are time, the curve and the angle" that you have three independent variables, if so you will have to adapt it quite a bit... But for one-variable problems, interp is the way to go.

Categories