I need to interpolate a in 3D and I want to do this only for the area where I actually have observed x and y values. This can be done in the following steps:
- Find outer points of the 2d x and y area (see my question here).
- Create a grid for interpolation but keep only grid points that lay inside the outer points of step 1.
- Interpolate.
Here an example:
In the first step I found out the outer points of the observed data (here observed data as big black points and the outer points in red). In a second step I generated a grid (small black points). Now I need to know which grid points lay inside the outer points area (which I here marked by connecting the red points with a red line). How to find those grid points?
Code and data
set.seed(3)
df <- data.frame(matrix(rnorm(100), ncol= 2))
library(ggplot2)
grid_df <- expand.grid(seq(min(df$X1), max(df$X1), length.out= 100),
seq(min(df$X2), max(df$X2), length.out= 100))
df$outer <- FALSE
df$outer[chull(df$X1, df$X2)] <- TRUE
ggplot() +
geom_point(data= df, mapping= aes(X1, X2)) +
geom_point(data= df[df$outer, ], mapping= aes(X1, X2), col= "red") +
geom_point(data= grid_df, mapping= aes(Var1, Var2), col= "black", size= .5)
Expected output is a third column in grid_df which is TRUE if the point lays inside the area. I look for a R base solution.


