I am searching for a utility in R which will determine the mean location of a closed contour and eventually record the location in an ASCII file. By means of the contour utility in R, I am able to produce an image of a contour, but I am seeking a procedure which will produce the coordinates of the center of mass of the contour. From my actual set of data, the contour utility will produce several hundered closed non-intersecting and non-concentric contours like a lattice of disks. I want the location of those disks via a program. Is there any package in R which will lend itself to this problem? Thank you, Charles Fleming
I think you have to roll your own. Best idea I can come up with is a classic application of Monte Carlo integration. Throw down a million (say) random points, uniformly distributed throughout the 2D region where the contours will be plotted. For each point, evaluate whether it is inside or outside the contours (equivalently, whether the surface being contoured is above or below the contour level at this point). Then calculate the sample mean of x coordinates, similarly y coordinates, for all points which map inside the contour. And ignore all random points which fall outside the contour. HTH - tom blackwell - u michigan medical school - ann arbor - On Wed, 19 Mar 2003, Charles M. Fleming wrote:> I am searching for a utility in R which will determine the mean location of > a closed contour and eventually record the location in an ASCII file. By > means of the contour utility in R, I am able to produce an image of a contour, > but I am seeking a procedure which will produce the coordinates of the > center of mass of the contour. From my actual set of data, the contour > utility will produce several hundered closed non-intersecting and > non-concentric contours like a lattice of disks. I want the location of > those disks via a program. Is there any package in R which will lend > itself to this problem? > > Thank you, > > Charles Fleming > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Although I had versions of the 2-D polygon centroid algorithm written in C and Fortran years ago, I can't find them today. The formula can be found at http://astronomy.swin.edu.au/~pbourke/geometry/polyarea/. Functions for calculating polygon area in R package "splancs" (function areapl) or in R package "tripack" (function voronoi.area), might be adaptable.> I am searching for a utility in R which will determine the meanlocation of> a closed contour and eventually record the location in an ASCII file.By> means of the contour utility in R, I am able to produce an image of acontour,> but I am seeking a procedure which will produce the coordinates of the > center of mass of the contour. From my actual set of data, the contour > utility will produce several hundered closed non-intersecting and > non-concentric contours like a lattice of disks. I want the locationof> those disks via a program. Is there any package in R which will lend > itself to this problem?