# [R-sig-Geo] Drawing spokes from a fixed point to the boundary of a polygon and take the maximum cut point

Kaushik Jana kaushikjana11 at gmail.com
Fri May 20 09:21:06 CEST 2016

```Hello everyone,

I am working with spatial polygon and using SP and RGEOS package. I am
having
problem to find the maximum-distance intersect points with spokes (drawn
from a kind of centroid) and the polygon boundary.

Thanks,
Kaushik

*Here is the details steps:*

Consider a 2-D polygon (with no holes) with the vertices

> X=
x                  y
[1,] -13.07387755  6.752311920
[2,]  -9.33770907   5.067708782
[3,]  -7.49002198   9.665618999
[4,]  -3.75490263   7.978791961
[5,]  -0.02026076   6.289741026
[6,]  -1.86977386   1.692942758
[7,]   1.86397021   0.001667924
[8,]   5.60020191   -1.689606910
[9,]   9.33298897   -3.380881745
[10,]  11.18475614  1.213692624
[11,]  14.91650047  -0.479806108
[12,]  13.06430891  -5.074380477
[13,]  11.21735861  -9.665618999
[14,]   7.48745370   -7.974344164
[15,]   3.75607922   -6.283069330
[16,]   0.02026968   -4.591794496
[17,]  -3.71404150   -2.901631611
[18,]  -7.44784360   -1.213692624
[19,] -11.18014866   0.472022464
[20,] -14.91491149   2.155513653
[21,] -13.07387755   6.752311920

Consider a point (centre of the convex hull of X):

>cent_0=c(0.4315245,0.3889576)

I am drawing equi-angled (around 360 degree of the centre) spokes from the
above centre to the vertices of the polygon.

*Here is my R-code to draw the spokes:*
>n=50  # Number of equi angled spokes from center
>xcent = cent_0[1]
>ycent = cent_0[2]
>cent = sp::SpatialPoints(cbind(xcent, ycent))
>pts = sp::SpatialPoints(X)
## take the furthest distance from centre to vertex, times two!
>r = 2 * max(sp::spDistsN1(pts, cent))
>theta=seq(0,2*pi,length=n+1)[-(n+1)]
## construct a big wheel of spoke lines
>sl = sp::SpatialLines(lapply(1:length(theta),function(id){
>t = theta[id]
>sp::Lines(list(sp::Line(rbind(c(xcent, ycent),c(xcent + r * cos(t),ycent +
r * sin(t))))),ID=id)}))
## construct the polygon as a SpatialPolygons object:
>pol=sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(rbind(xy,xy[1,]))),ID=1)))
## overlay spokes on polygon as "SpatialLines" so we do line-on-line
## intersect which gets us points
>spokes = rgeos::gIntersection(sl, as(pol,"SpatialLines"), byid=TRUE)
>spokes

I want to have the maximum-distance intersect points with the spokes and
the polygon boundary.  If a spoke (corresponding to a specific angle) don't
intersect the boundary of the polygon then we take the intersect point as
the centre itself for that angle.

So finally I want to have *n *boundary points on the (one for each angle)
polygon which obtained from the  above scheme.

Stuck here in doing this.

Any suggestions!!

[[alternative HTML version deleted]]

```