Hi all, I have a matrix of a mountain of form 21x21 and values in them are height (Z). Using the persp function I can view this mountain in 3D. Now, I am trying to find a measure to find the centre of gravity (maybe centroid?) of this mountain. Any idea what would be the best way to go? -- View this message in context: http://r.789695.n4.nabble.com/Centre-of-gravity-of-a-mountain-tp3032319p3032319.html Sent from the R help mailing list archive at Nabble.com.
Weighted mean of x and y coordinates (sorry for the pun :)), that is something like n = 21 y = matrix( c(1:n), n, n) x = matrix( c(1:n), n, n, byrow = TRUE) # These are the Center of mass coordinates: xCenter = sum(x * Z)/sum(Z); yCenter = sum(y * Z)/sum(Z); If you also need the z coordinate, it simply the mean of the matrix Z. zCenter = mean(Z) Peter On Mon, Nov 8, 2010 at 9:07 AM, Ab Hu <master.rstat at yahoo.com> wrote:> > Hi all, > I have a matrix of a mountain of form 21x21 and values in them are height > (Z). Using the persp function I can view this mountain in 3D. > Now, I am trying to find a measure to find the centre of gravity (maybe > centroid?) of this mountain. Any idea what would be the best way to go? > -- > View this message in context: http://r.789695.n4.nabble.com/Centre-of-gravity-of-a-mountain-tp3032319p3032319.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Mon, Nov 8, 2010 at 5:15 PM, Peter Langfelder <peter.langfelder at gmail.com> wrote:> If you also need the z coordinate, it simply the mean of the matrix Z. > > zCenter = mean(Z)How can that be right? Suppose your mountain is very flat, so that your mountain is effectively a cube. The Z values are all the same, and so their mean is the same. However the centre of mass is, by symmetry, clearly at height/2. Similarly suppose your mountain matrix is one large cell value and all the rest are near zero - the mean Z will be close to zero but the centre of mass will be almost half way up the single cell value, because all the near-zeros contribute nothing to the centre of mass position. Barry
On Tue, Nov 9, 2010 at 3:40 PM, Barry Rowlingson <b.rowlingson at lancaster.ac.uk> wrote:> On Mon, Nov 8, 2010 at 5:15 PM, Peter Langfelder > <peter.langfelder at gmail.com> wrote: > >> If you also need the z coordinate, it simply the mean of the matrix Z. >> >> zCenter = mean(Z) > > ?How can that be right? Suppose your mountain is very flat, so that > your mountain is effectively a cube. The Z values are all the same, > and so their mean is the same. However the centre of mass is, by > symmetry, clearly at height/2. > > ?Similarly suppose your mountain matrix is one large cell value and > all the rest are near zero - the mean Z will be close to zero but the > centre of mass will be almost half way up the single cell value, > because all the near-zeros contribute nothing to the centre of mass > position.Yup, the z coordinate is wrong. Only the x and y are right. Peter
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Peter Langfelder > Sent: Tuesday, November 09, 2010 3:49 PM > To: Barry Rowlingson > Cc: r-help at r-project.org; Ab Hu > Subject: Re: [R] Centre of gravity of a mountain > > On Tue, Nov 9, 2010 at 3:40 PM, Barry Rowlingson > <b.rowlingson at lancaster.ac.uk> wrote: > > On Mon, Nov 8, 2010 at 5:15 PM, Peter Langfelder > > <peter.langfelder at gmail.com> wrote: > > > >> If you also need the z coordinate, it simply the mean of the matrix > Z. > >> > >> zCenter = mean(Z) > > > > ?How can that be right? Suppose your mountain is very flat, so that > > your mountain is effectively a cube. The Z values are all the same, > > and so their mean is the same. However the centre of mass is, by > > symmetry, clearly at height/2. > > > > ?Similarly suppose your mountain matrix is one large cell value and > > all the rest are near zero - the mean Z will be close to zero but the > > centre of mass will be almost half way up the single cell value, > > because all the near-zeros contribute nothing to the centre of mass > > position. > > Yup, the z coordinate is wrong. Only the x and y are right. > > Peter >I believe that should have been mean(z)/2 Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204