-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Hello, I now want to perturb randomly generated points within a polygonal area. I've written the perturbation algorithm, but I can't guarantee that the perturbed points are still inside the polygon area. I think that when using spsample, it is guaranteed to be in candidates. I want to know how I can implement this. My own design only ensures that the xy of the perturbed points are within x_bound and y_bound respectively. Below is my code.
x_bound = bbox(candidates)[1, ] y_bound = bbox(candidates)[2, ] x_extent = x_bound[2] - x_bound[1] y_extent = y_bound[2] - y_bound[1] temp_pt[j,1] = curr_pt[j,1] + x_extent * runif(1, -0.2, 0.2) while(temp_pt[j,1] < x_bound[1] || temp_pt[j,1] > x_bound[2]){ temp_pt[j,1] = curr_pt[j,1] + x_extent * runif(1, -0.2, 0.2) } temp_pt[j,2] = curr_pt[j,2] + y_extent * runif(1, -0.2, 0.2) while(temp_pt[j,2] < y_bound[1] || temp_pt[j,2] > y_bound[2]){ temp_pt[j,2] = curr_pt[j,2] + y_extent * runif(1, -0.2, 0.2) }
