[R] Slope of surface
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Wed Oct 20 01:49:33 CEST 2004
On 19-Oct-04 Laura Quinn wrote:
> Is there a neat way of working out the slope of a flat surface in R?
> Given (x,y,z) co-ordinates of the four corners of a square, is there a
> function which will allow me to calculate the "mean" slope of the
> surface in a given direction?
Presumably you mean the z-slope in a direction defined by changes
in x and y.
Suppose the corners of the square (doesn't have to be square but
at least we know where we stand) are numbered in order round the
square as
(x1,y2,z1), (x2,y2,z3), (x3,y3,z3), (x4,y4,z4)
(As Uwe suggests, you only need three). It makes it simpler and
doesn't change the problem to suppose that (x1,y1,z1) = (0,0,0).
Let your direction be defined by a move in the (x,y) plane from
(0,0,0) to (u,v,0), with the corresponding point in the square
given by (u,v,w). Then the slope is w/sqrt(u^2 + v^2).
Clearly w is linear in u and v with zero "intercept". Hence
w = a*u + b*v
and at points [2] and [4] you have
a*x2 + b*y2 = z2
a*x4 + b*x4 = z4
so, if you let M = matrix(c(x2,x4,y2,y4),nrow=2)
and A = c(z2,z4)
then (a,b) is given by solve(M,A). Provided the columns of M
are linearly independent (ensured by "square") this has a clean
solution for (a,b) and then you have it. (Note point [3] has not
been used.)
I think!
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861 [NB: New number!]
Date: 20-Oct-04 Time: 00:49:33
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list