Hi R experts! I have a cloud of points scattered in a 2D Euclidean space. I would like to calculate the area inside the polygon linking the most extreme (=peripheral) points of the cloud. In other words, I would like to estimate the area covered by the cloud in this space. Is there a formula in R? Thanks a lot for any response Julien
+5
A:
This is called the convex-hull problem; R built-in chull
function should do the work. To count area, you may use a formula from here.
EDIT: Even better; splancs
package has areapl
function. So the function solving your problem should look like this:
cha<-function(x,y){
chull(x,y)->i
return(areapl(cbind(x[i],y[i])))
}
For instance:
library(splancs);
x<-rnorm(20);rnorm(20)->y;
#Some visualization
i<-chull(x,y);plot(x,y);polygon(x[i],y[i]);
#The area
cha(x,y);
mbq
2010-09-08 22:15:04
If you like it, accept the answer (green tick mark) -- and use comments, not post new answers.
mbq
2010-09-09 09:02:17
Also, you could try creating a profile and logging in (otherwise you will not get to see the tick mark mentioned by mbq, I guess), instead of continue to use StackOverflow as a distinct set of unregistered users.
peSHIr
2010-09-09 09:07:16
@mbq: seems like somebody lost his password and had to create a new username. hence, no accepting: "Julien R" vs "julien" ...
Henrik
2010-09-09 09:08:46
@Henrik missed that; identicons do deceive ;-)
mbq
2010-09-09 09:21:45