-1

I have a problem with fitting a curve in 3D point set (or point cloud) in space. When I look at curve fitting tools, they mostly create a surface when given a point set [x,y,z]. But it is not what I want. I would like to fit on point set curve not surface.

So please help me what is the best solution for curve fitting in space (3D).

Particularly, my data looks like polynomial curve in 3d.

Equation is

z ~ ax^2 + bxy + cy^2 + d

and there is not any pre-estimated coefficients [a,b,c,d].

Thanks.

xyz <- read.table( text="x y z
518315,750 4328698,260 101,139
518315,429 4328699,830 101,120
518315,570 4328700,659 101,139
518315,350 4328702,050 101,180
518315,3894328702,849 101,190
518315,239 4328704,020 101,430", header=TRUE, dec=",")

sample image is here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
Muzo583
  • 31
  • 6
  • 1
    I think you need to define what you mean by a "#D point set curve" that is not a surface. Given the lack of any data there's really nothing to be done yet. – IRTFM Aug 23 '16 at 07:11
  • It is a sort of multivariate regression line but I could not implement R and matlab linear models to my function. – Muzo583 Aug 23 '16 at 07:51
  • I don't understand the question. The equation you provide describes a surface. It's easy enough to fit the parameters using `lm(z ~ I(x^2) + x:y + I(y^2), data = yourdata)`, but it is still a surface as long as you do not impose any constraints on `x` and `y`. – Roland Aug 23 '16 at 08:08
  • Perhaps you mean fit the data to a 1D manifold (sometimes called a "space curve"? With the correct transformation that could be line in 3-space. – IRTFM Aug 23 '16 at 21:42

2 Answers2

2

With a bit of data we can now demonstrate a rather hackis effort in the direction you suggest, although this really is estimating a surface, despite your best efforts to convince us otherwise:

xyz <- read.table(text="x y z

 518315,750 4328698,260 101,139
 518315,429 4328699,830 101,120
 518315,570 4328700,659 101,139
 518315,350 4328702,050 101,180
 518315,389 4328702,849 101,190
 518315,239 4328704,020 101,430", header=TRUE, dec=",")
 lm( z ~ I(x^2)+I(x*y) + I(y^2), data=xyz)
#---------------

Call:
lm(formula = z ~ I(x^2) + I(x * y) + I(y^2), data = xyz)

Coefficients:
(Intercept)       I(x^2)     I(x * y)       I(y^2)  
 -1.182e+05   -3.187e-07    9.089e-08           NA  

The collinearity of x^2 and x*y with y^2 is preventing an estimate of the y^2 variable coefficient since y = x*y/x. You can also use nls to estimate parameters for non-linear surfaces.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
0

I suppose that you want to fit a parametrized curve of of this type:

r(t) = a + bt + ct^2

Therefore, you will have to do three independent fits:

x = ax + bx*t + cx*t^2
y = ay + by*t + cy*t^2
z = az + bz*t + cz*t^2

and obtain nine fitting parameters ax,ay,az,bx,by,bz,cx,cy,cz. Your data contains the positions x,y,z and you also need to include the time variable t=1,2,3,...,5 assuming that the points are sampled at equal time intervals.

If the 'time' parameter of your data points is unknown/random, then I suppose that you will have to estimate it yourself as another fitting parameter, one per data point. So what I suggest is the following:

  1. Assume some reasonable parameters a,b,c.
  2. Write a function which calculates the time t_i of each data point by minimizing the square distance between that point and the tentative curve r(t).
  3. Calculate the sum of all (r(t)-R(t))^2 between the curve and your dataset R. This will be your fitting score, or the Figure of Merit
  4. use Matlab's genetic algoritm ga() routine to obtain an optimal a,b,c which will minimize the Figure of Merit as defined above

Good luck!

  • Thank you for your answer. I have heard some solution as your proposed. But I do not have any time variable. Maybe the solution can be interpolate (or fitting) 2 dimensional x-y, x-z, y-z and combine them.However, there is existing another problem , that how to combine 3 different nonlinear model into 3 dimensional coordinate system.. – Muzo583 Aug 23 '16 at 13:28
  • I wonder if a sort operation could be done first if there was an assumption of progressing increase of x,y and z? Then the t parameter could be as you described. – IRTFM Aug 23 '16 at 21:29