Finding z-coordinate of a point on a surface

2 views (last 30 days)
I have generated a surface [AX, AY, AZ], where AX, AY, AZ are NxN doubles. How to find z-coordinate of a particular point on the surface for given values of x- and y- coordinates using MATLAB's 'roots' function? Can the projection of the surface be taken on z-axis to find the z-coordinate? If yes, how?

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2013
It is possible. I am not certain there is a "nice" way to do it with roots(), though.
If you make algebraic substitutions so u = (ii-1)/10 and v = (jj-1)/10 then U = [u^4 u^3 u^2 u 1] and V = [v^4 v^3 v^2 v 1]. You can write out the X matrix as [x11 x12 x13 x14 x15; x21 x22 x23 etc] and likewise for Y and Z. You can then expand U*X*V' to get an expression that must logically be a scalar. Equate this expression to the known x value and solve for ii . As one might expect from the fact that U and V both involve 4th orders, the result will be ii in terms of the roots of a 4th order expression in jj. As quartics have exact analytic forms, even though they are long, you can express the four roots of ii in terms of jj. Then take each of the four roots of ii in turn and substitute for ii in the expanded U*Y*V' and equate the result to the known y value, and solve for jj; again each of those will be a quartic for which exact roots can be found. But this time there are no symbolic variables involved, so one can use roots() to find the numeric solutions. Possibly getting nonsense due to numeric round-off problems, but if the problem demands roots() then the problem demands roots(). Now the numeric roots found for jj can be propagated upwards and roots() used to find the corresponding ii values. Logically one might end up with 16 different ii values (four complex root equations, each in terms of four complex roots); any time I have done this kind of substitution myself I have only ended up with 4 distinct solutions instead of 16, but that might have been due to chance.
With ii and jj values in hand, the ii and jj can be substituted into the algebraic formulation of U*Z*V' to find the z coordinates of the surface.
It would take a deeper algebraic examination in order to determine if check if whenever X and Y and Z are real and the known x and y are real, then is it the case that must there be exactly one solution with positive real ii and jj? Remember that in theory substituting complex jj values into the expression for ii could happen to have all of the complex portions cancel out leaving a real solution. But there might be deeper reasons why that situation cannot occur in this problem.
  1 Comment
Sahil
Sahil on 13 Aug 2013
Edited: Sahil on 13 Aug 2013
Thanks, your answer was very helpful to find out the z-coordinates. What I have done right now is that I have computed U and V in terms of ii and jj respectively. Then I have solved two equations:
syms ii jj
S = solve('U*X*transpose(V) = x', 'U*Y*transpose(V) = y');
Please note that the above expression has to contain the values of U*X*V.' and U*Y*V.' rather than U*X*V.' and U*Y*V.' themselves.
It gives 32 values of ii and jj each, out of which some are complex values. Then, I have computed U and V corresponding to the real values of ii and jj and calculated U*Z*V.'
I couldn't use roots() function because of the following issues:
1. If I were to take the coefficients of powers of ii (in terms of jj), I would use coeffs(). The output of this function is the coefficients arranged from 0 to highest power, but more importantly, it doesn't give 0 for missing powers.
2. roots() function didn't allow a sym jj in its expression.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 12 Aug 2013
Why are Ax, Ay, and AZ 2-dimensional matrices??? Wouldn't they be 1-D vectors? If they are 1-D, just index into the N-by-2 array
Z = yourArray(AX, AY);
If your AX and AY are not in your matrix, then you might use TriScatteredInterp() or similar functions to interpolate Z values for coordinates that are not explicitly given in your array.
  4 Comments
Walter Roberson
Walter Roberson on 12 Aug 2013
When you say you have "generated" the surface, does that mean you have the equation of the surface? If so then is it allowed to make use of the equation in finding the needed point? Is the surface a multinomial? If so does it have any Ax^N * Ay^M terms, or only Ax^N and Ay^M terms ?
Sahil
Sahil on 12 Aug 2013
The surface is actually a Bezier surface which is generated like this:
m = 5; n = 5;
for ii = 1 : 11
u = 0.1*(ii-1);
for k = 1 : n
U(k) = u^(n-k);
end
for jj = 1 : 11
v = 0.1*(jj-1);
for k = 1 : m
V(k) = v^(m-k);
end
Ax(ii,jj) = U*X*V';
Ay(ii,jj) = U*Y*V';
Az(ii,jj) = U*Z*V';
end
end
where X, Y, Z are 5x5 matrices.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!