Hi Alex, I remember that you had the discussion recently about identifying grid cells that were crossed by a line...
http://tolstoy.newcastle.edu.au/R/e11/help/10/09/8431.html So, following on from those posts, for any cell crossed by a line you will know the coordinates of the cell corners and the densified vertices of the line (referring to David W's approach of using a sequence of points along the line). You could then use the following simple function to get the area of the polygon defined by those coordinates... function(x, y=NULL) { # Calculate unsigned area of a simple (ie. no holes) polygon # # x, y vertex coordinates coords <- xy.coords(x, y) x <- coords$x y <- coords$y N <- length(x) if (!(x[1] == x[N] & y[1] == y[N])) { x <- c(x, x[1]) y <- c(y, y[1]) N <- N + 1 } px <- sum(x[-N] * y[-1]) py <- sum(y[-N] * x[-1]) abs((px - py) / 2) } The position of your cells and lines in the real number plane will determine which cell corners you include with the line vertices to calculate an area appropriate for your integral. Michael On 6 October 2010 01:31, Alaios <ala...@yahoo.com> wrote: > Hello > I would like to calculate a weighted line integral. > The integral is calculated by the cells that this lines trasverses (the small > cells belong to matrix (m*n) that represent the value that a specific area > has. > > I need to calculate the weights by finding out how much the line touches or > impinges inside a cell. > The weight is less if a line just touches one of the four edges of a square > and > much more if it traverses inside the cell. I think there might be some > function > to calculate this in any image processing packages. > So far I could not find anything appropriate. > Could you please help me with that? > > I would like to thank you in advance for your help > Best Regards > Alex > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.