Find multivariable function from surface - wolfram-mathematica

I have a table of over 250,000 (x, y, z) coordinates. I'm trying to apply the gradient to find surface characteristics, but I don't know how to obtain the function for the data. It's a pretty complex surface btw, so Mathematica might not even be able to get the function whatsoever.

Related

Indexing image according to polar coordinates?

Ok, this might be a little dumb to ask but I'm really having a hard time understanding the image coordinates in Matlab.
So, in a mathematical equation, f(x,y) f is the image function where x and y are the coordinates of the image. For example, in matlab code, we can:
img = imread('autumn.tif');
img(1,4); %f(x,y)
where img(1,4) is equivalent to the function f(x,y). Now, in Matlab, there is an option to convert the cartesian coordinate (x,y) to polar coordinate (rho,theta) with cart2pol() function.
Now, here's where I don't understand. Is it possible to apply f(rho,theta) which is the polar coordinates instead of the cartesian coordinate in Matlab?
I tried doing something like:
img(2.14,1.5)
But I get the error message saying about array indexing is only supported with integers or logical values.
Could anyone clear up my understanding on this? Because I'm required to apply f(rho,theta) instead of the conventional f(x,y).
An image in Matlab is basically just an 2D array (if you consider just a greyscale image). Therefore you also need integer indices, just as for all other arrays, to access the pixels of the image.
% i,j integers, not doubles, floates, etc.
pixel = img(i,j);
The polar coordinates from yor last question (theta, rho) can therefore not be used to access the image array. That is also the exact reason for the error message. At least you'd need to round them or find some other way to use them as indices (e.g. convert them back to cartesian coords. would be best, due to matrix indexing)
Regarding your application: As far as I have found out, these polar coordinates are used as parameters for the Zernike polynomials. So why would you use them to access the image?

Plotting a location into an irregular rectangle

I have 4 Point values: TopLeft, TopRight, BottomLeft, BottomRight. These define a 4 sided shape (like a distorted rectangle) on my monitor. These are the point a Tobii gaze device thinks I am looking at when in fact I am looking at the four corners of my monitor.
This picture shows a bitmap on the left representing my monitor, and the points the Tobii device tells me I am looking at when I am in fact looking at the corners of the screen. (It's a representation, not real).
I want to use those four calibration points to take a screen X,Y position that is from an inaccurate gaze position and correct it so that it is positioned as per the image on the right.
Edit: New solution for the edited question is at the end.
This problem is call bilinear interpolation.
Once you grasp the idea, it will be very easy and you would remember it for the rest of your life.
It would be quite long to post all detail here, but I will try.
First, I will name the point on the left to be (x,y) and the right to be (X,Y).
Let (x1,y1), (x1,y2), (x2,y1), (x2,y2) be the corner points on the left rectangle.
Secondly, let's split the problem into 2 bilinear interpolation problems:
want to find X
want to find Y
Let's find them one by one (X or Y).
Define : Qxx are the value of X or Y of the four corner in the right rectangle.
Suppose that we want to find the value of the unknown function f at
the point (x, y). It is assumed that we know the value of f at the
four points Q11 = (x1, y1), Q12 = (x1, y2), Q21 = (x2, y1), and Q22 =
(x2, y2).
The f(x,y) of your problem is X or Y in your question.
Then you interpolate f(x,y1) and f(x,y2) to be f(x,y) in the same way.
Finally, you will got X or Y=f(x,y)
Reference : All pictures/formulas/text here are copied from the wiki link (some with modification).
Edit: After the question has been edited, it become very different.
The new one is opposite, and it is called "inverse bilinear interpolation" which is far harder.
For more information, please read http://www.iquilezles.org/www/articles/ibilinear/ibilinear.htm
You can define a unique Linear Transform using 6 equations. The 3 points which have to align provide those 6 equations, as each pair of matching points provides two equations in x and y.
If you want to pursue this, I can provide the matrix equation which defines the Linear Transform based on how it maps three points. You invert this matrix and it will provide the linear transform.
But having done that, the transform is completely specified. You have no control over where the corner points of the original quadrilateral will go. In general, you can't even define a linear transform to map one quadrilateral onto another; this gives 8 equations (2 for each corner) with only 6 unknowns. Its over-specified. In fact a Linear Transform must always map a rectangle to a parallelogram, so in general you can't define a Linear Transform which maps one quadrilateral to another.
So if it can't be a Linear Transform, can it be a non-Linear Transform? Well, yes, but non-Linear Transforms don't necessarily map straight lines to straight lines, so the mapped edges of the quadrilateral won't be straight. Or any other lines. And you still have 14 equations (2 for each point and corner) for which you have to invent some non-Linear transform with 14 unknowns.
So the problem as stated cannot be solved with a Linear Transform; its over specified. Using a non-Linear transform will require you to devise a non-Linear transform which has 14 free variables (vs the 6 in a Linear Transform), this will map the 7 points correctly but straight lines will no longer be straight. Adding this requirement in adds an infinite number of constraints (one for every point in the line) and you won't even be able to use continuous functions.
There may be some solution to what you are doing in terms of what you are really trying to do (ie the underlying application need), but as a mathematical problem it is unsolvable.
Let me know if you want the matrix equation to produce a Linear Transform based on how it transforms 3 points.

How to design an algorithm to linear interpolate points in 3D space and create an indented surface?

I am trying to develop a function that takes a matrix of input, out a contour plot as an output. There is a function in matlab which fits to my purpose. But for a self-examination method, I would like to do this myself. Like I said, my purpose is self-examination, I will not use this in an app or something.
Here is the deal, I have tried to do this with color maps, but what I got is a graph that seems like an uncalibrated TV channel:
(source: yeniakit.com.tr)
Graph is like that because, my function is discrete. I need to make this discreet function continuous.
I found a solution to this problem. Solution uses linear interpolation method to connect each point with each other. Surface created this way will have lots of rough edges but that is not a problem. Connecting the points in the space to create surfaces is OK, but those surfaces also has point on them. Computing such a thing would be very expensive, since a lot of computations involved. For example, lets say, I would like to create a surface by using 20x20 matrix. Rows and columns will be the x and y coordinates, values in each row and column will be the z coordinate.
I need to connect at least 3 dots to make a surface. Those surfaces have also points in them. I want to design such an algorithm that reduces the computations. How do I do that?

How to get angle rotated of a 3D object from its transform martrix

I have a 3d object which is free to rotate along x,y and z axis and it is then saved as a transform matrix. In a case where the sequence of rotation is not known and the object is rotated for more than 3 times (eg :-if i rotate the object x-60degress, y-30 degrees, z-45 degrees then again x->30 degrees), is it possible to extract the angles rotated from the transform matrix?.I know that it is possible to get angles if the sequence of rotation is known, but if I have only the final transform matrix with me and nothing else, is it possible to get the angles rotated(x,y,and z) from the transform matrix ?
Euler angle conversion is a pretty well known topic. Just normalize the matrix orientation vectors and then use something like this c source code.
The matrix is the current state of things it has no knowledge of what the transformation has been in the past. It does not know how the matrix was built. You can just take the matrix into and decompose it into any pieces you like, as long as:
The data do not overlap. For example:Two X turns after each other is indistinguishable form each other (no way to know if its 1 2 or three different rotations summed).
The sequence order is known
A decomposition can be built out of the data (for example scale can be measured)

How to draw Gaussian Distribution curve

I want to draw a Gaussian Distribution curve, i know
p(x) = (1/σRoot(2π)) x exp (- (x-μ)2/2σ2),
i got the mean and standard deviation, but now i don't know how to proceed, how this bell-graph will be drawn, from where to get the co-ordinates, what's the use of above formula.
I searched a lot on internet and got nothing, every where it's given that how to draw it in excel or in matlab, but nowhere i found how those co-ordinates are got and how those curves are drawn.
if anyone can give me any idea on this it will be of great help.
A graph is simply a set of points plotted on the plane. So basically what you do is pick a set of x-coordinates that you want to plot the curve on. Then plug those x values into your function p(x) to get the y-coordinates.
Lastly, plot the resultant points.
Most graphing software (like your standard graphing calculator) will automate all this functionality for you.

Resources