How to fit a line through a 3D pointcloud?

2024/10/11 0:25:35

I have a cable I am dropping from moving vehicle onto the ground. Using a camera system I estimate the location where the rope touches the ground in realtime. Movement of the vehicle and inaccuracy in the estimation of the location result in a point-cloud of touchdown locations. From this point cloud, I'd like to obain the most likely path of the cable lying on the ground. I'd like to achieve this in real-time, and I'd like the fit to be updated according to new data. The frequency of new points being added is approximately 20 Hz, whereas the movement speed of the vehicle is about 1 m/s. Therefor the point cloud is rather dense. The path followed by the cable on the ground is smooth (since the cable is stiff) and in 3D (x,y,z: the ground is not flat!).

I've been looking for 3D line/spline/curve fit/interpolation. I have found some promising methods (B-spline fits, LOWESS -> seems viable, is available in 2D, but not in 3D). However I can not find any clear explanation on what method would be suited for my case. What fitting method would you suggest for this situation?

The current dataset I'm working on is generated by:

import numpy as nptMax = 10 # s
f = 20 # hz
v = 2 # m/s
samples = tMax*f
t = np.linspace(0,tMax, samples)
div = 00.[![2][2]][2]
x=1*np.sin(t)+t+np.random.uniform(-div,div,samples)
y=1*np.cos(t)+t+np.random.uniform(-div,div,samples)
z=1*np.sin(t)*np.cos(t)+t+np.random.uniform(-div,div,samples)

enter image description here

I manage to obtain reasonable results with LOWESS in 2D, as can be seen in the image below, but not 3D.

enter image description here

Another thing I might add is that the data is time-stamped. I can imagine this might be benificial in fitting the line.

Answer

You can use scipy UnivariateSpline.

from scipy.interpolate import UnivariateSpline# new axis
u = np.arange(len(x))# UnivariateSpline
s = 0.7 * len(u)     # smoothing factor
spx = UnivariateSpline(u, x, s=s)
spy = UnivariateSpline(u, y, s=s)
spz = UnivariateSpline(u, z, s=s)
#
xnew = spx(u)
ynew = spy(u)
znew = spz(u)
https://en.xdnf.cn/q/69836.html

Related Q&A

Websockets with Django Channels on Heroku

I am trying to deploy my app to heroku. The app has a simple chatting system that uses Websockets and django channels. When I test my app using python manage.py runserver the app behaves just as intend…

How can I get the name/file of the script from sitecustomize.py?

When I run any Python script, I would like to see the scripts filename appear in the Windows command line windows titlebar. For example, if I run a script called "mytest.py", I want to see &q…

Sending Godaddy email via Django using python

I have these settings EMAIL_HOST = smtpout.secureserver.net EMAIL_HOST_USER = [email protected] EMAIL_HOST_PASSWORD = password DEFAULT_FROM_EMAIL = [email protected] SERVER_EMAIL = [email protected] EM…

python math, numpy modules different results?

I get slightly different results calculating the cosine of a value. How can I check that this difference is within machine precision?import math math.cos(60.0/180.0*math.pi) -> 0.5000000000000001im…

How to extract equation from a polynomial fit?

My goal is to fit some data to a polynomial function and obtain the actual equation including the fitted parameter values. I adapted this example to my data and the outcome is as expected. Here is my c…

python dictionary conundrum

On the console I typed in>>> class S(str): pass ... >>> a = hello >>> b = S(hello) >>> d = {a:a, b:b} >>> d {hello: hello} >>> type(d[a]) <class…

Celery 4 not auto-discovering tasks

I have a Django 1.11 and Celery 4.1 project, and Ive configured it according to the setup docs. My celery_init.py looks likefrom __future__ import absolute_importimport osfrom celery import Celery# set…

Is it possible to use a custom filter function in pandas?

Can I use my helper function to determine if a shot was a three pointer as a filter function in Pandas? My actual function is much more complex, but i simplified it for this question.def isThree(x, y…

what is request in Django view

In the Django tutorial for the first app in Django we havefrom django.http import HttpResponsedef index(request):return HttpResponse("Hello, world. Youre at the polls index.")And then the url…

Cannot update python package on anaconda to latest version

Some of my python packages on anaconda cannot be updated to the latest version.For instance, beautifulsoup4 latest version on anaconda is v4.71 as seen in the release notes. https://docs.anaconda.com/a…