R packages to fit three dimensional data using radial basis functions - r

I'm interested in fitting a three dimensional surface to some spatial data (x, y, z) using a radial basis function approach. I have found that radial basis functions apppear in the R package 'fields' but would like to find an example where it has been used to fit a surface to points in three dimensions. I would thankful if somebody could point me towards or provide a simple example that I could use as a start.

Related

Model a 3D Point Pattern using spatstat

Is there any way to fit a spatial statistical model to 3d data in spatstat?
I have tried using the functions such as ppm and kppm but they are not working for pp3
This is not yet supported in spatstat (that is, the model-fitting functions ppm, kppm and mppm do not accept three-dimensional point pattern data).
We are working on it.

Drawing 3D eigenvectors in R

I'm currently attempting to construct a 3D confidence region based on the following quadratic form;
confidence region for mean mu
while I have the ellipsoid part figured out; I can't seem to figure out a way to include the major and minor axis. As per the textbook I'm using, the major axis is
length of major axis units in the direction of $e_i$--the ith eigenvector of the estimate of the covariance matrix S. For plotting the ellipsoid, I used the following code that required the rgl package:
plot3d(ellipsoid(mu_1,S_1,(((n-1)*p)/(n-p))*(qf(0.05,df1=p,df2=n-p,lower.tail = FALSE)),segments=100),alpha=0.5,color='blue')
But I believe the function creates its own 3D mesh object within which it produces the ellipse, so I'm having a lot of trouble constructing the 3D eigenvectors on the same 3D plane. In fact, even if I completely abandon the ellipsoid part, I can't seem to find a way to even just draw out the 3D eigenvectors centered at $\bar{x}$. I've loaded packages like plotly and matlib and even tried something as dumb as defining a 3D parametric function of a line that went as follows:
lines <- function(x0,a){ t <- seq(0,1,length=10000) return(matrix(x0+c(a[1]*t,a[2]*t,a[3]*t),nrow=10000,ncol=3,byrow=TRUE)) }
I then went ahead with the plot3d function, to no avail. Any help would be appreciated!

How do I find the corner points of the feasible region for a system of linear inequalities [R]?

My system has only two variables, and I want to plot the polygon in a custom 2D plot.
I suppose it's very tightly connected with linear programming, so I checked the lpSolve package, but there is no way:
not to enter the objective function
not to run the optimization
to retrieve the corner points. I'm not sure if the solver calculates them all anyways.
There is also a method solve2dlp in the package intpoint that actually plots something alike, but somehow I cannot get through the code to check what exactly is it doing..

Creating a smooth nurb from list of points

I am developing a 3D graphic application in which the user can draw curves.
I record the curve that is drawn by the user and i would like to create a smooth nurb from the recorded set of points.
I tried using the openNurbs library but i could not find a way to do the fitting using the library.
How can i fit a set of points to a nurb?
First of all, I don't think you need nurbs. Fitting a B-spline curve to your data points should be good enough.
If you only have a few dozen points, then it is likely you would like the B-spline curve to exactly pass thru these data points. In this case, you are looking for spline interpolation algorithms. If this is the case, you can use Catmull Rom spline or Overhauser spline to interpolate your data points. Both will create C1 cubic splines and both are easy to implement without the need to solve a linear equation set.
If you have several hundreds of points, then it is likely that you only want the B-spline curve to lie close to the data points. Then, the algorithm you are looking for is least square fitting. You can find plenty of articles (e.g.: link1 ) in this area online. A typical algorithm for least square fitting with B-spline curve will involve these steps:
1) Choose a parametrization for your data points. Chord length parametrization is typically a good choice for least square fitting.
2) Choose the degree for the B-spline. Typically, we use degree 3, i.e., cubic B-spline.
3) Decide number of control points for your B-spline.
4) Decide the knot vector based on the information in the first 3 steps.
5) Solve a linear equation set to find the control points of the B-spline.

Rendering 3D surfaces

I've got data representing 3D surfaces (i.e. earthquake fault planes) in xyz point format. I'd like to create a 3D representation of these surfaces. I've had some success using rgl and akima, however it can't really handle geometry that may fold back on itself or have multiple z values at the same x,y point. Alternatively, using geometry (the convhulln function from qhull) I can create convex hulls that show up nicely in rgl but these are closed surfaces where in reality, the objects are open (don't completely enclose the point set). Is there a way to create these surfaces and render them, preferably in rgl?
EDIT
To clarify, the points are in a point cloud that defines the surface. They have varying density of coverage across the surface. However, the main issue is that the surface is one-sided, not closed, and I don't know how to generate a mesh/surface that isn't closed for more complex geometry.
As an example...
require(rgl)
require(akima)
faultdata<-cbind(c(1,1,1,2,2,2),c(1,1,1,2,2,2),c(10,20,-10,10,20,-10))
x <- faultdata[,1]
y <- faultdata[,2]
z <- faultdata[,3]
s <- interp(x,z,y,duplicate="strip")
surface3d(s$x,s$y,s$z,col=a,add=T)
This creates generally what I want. However, for planes that are more complex this doesn't necessarily work. e.g. where the data are:
faultdata<-cbind(c(2,2,2,2,2,2),c(1,1,1,2,2,2),c(10,20,-10,10,20,-10))
I can't use this approach because the points are all vertically co-planar. I also can't use convhulln because of the same issue and in general I don't want a closed hull, I want a surface. I looked at alphashape3d and it looks promising, but I'm not sure how to go about using it for this problem.
How do you determine how the points are connected together as a surface? By distance? That can be one way, and the alphashape3d package might be of use. Otherwise, if you know exactly how they are to be connected, then you can visualize it directly with rgl structures.

Resources