Calculate points with angle and distance from a centroid

Here is just a small r-script, which calculates the location of points around a centroid. I had problems with a dataset containing only the angle and the distance of the points and not their exact location. In my case the dataset represents a little forest survey with trees occurring in a given distance from the plots centroid.


bsp_sel # my plot data
trueCentroids = gCentroid(bsp_sel,byid=TRUE)



My Buffered plot and its centroid

# data structure:
# Species | Distance (in m) | Angle (in radians degree)
## For example
# Spruce | 20.5 | 66
centerPoint <- coordinates(trueCentroids)

# Function to calculate for instance the coordinates of the point in 20.5m by 66° from the coordinates of the centerpoint
retPoCordinates <- function(center,angle,distance){
x <- round(centerPoint[,1] + distance * cos(angle),0)
y <- round(centerPoint[,2] + distance * sin(angle),0)
result <-,y));names(result) <- c("x","y")

pp <- retPoCordinates(centerPoint,data$angle,data$distance) #Saves the coordinates of all trees in the variable pp
coordinates(pp) <- ~x+y
points(pp,col="green4",pch=19) # Add to plot
Plot with all trees around the centroid

Plot with all trees around the centroid

#If you want you could furthermore save your SpatialPoint Object as Esri shapefile. Use the tree species as attribute-table
#and the spatial projection from your first shape
spp <- SpatialPointsDataFrame(coords=coordinates(pp),$Species),proj4string=CRS(proj4string(bsp_sel)))
writeOGR(spp,"shapes","treepoints",driver="ESRI Shapefile",)

# Besides you could now calculate a distance matrix between the points or make a test for spatial aggregation and so on...


# ...

Go 4 it ! 😉


Tags: , ,

About Martin Jung

PhD researcher at the University of Sussex. Interested in nature conservation, ecology and biodiversity as well as statistics, GIS and 'big data'
Sussex Research Hive

Supporting the research community at the University of Sussex

Small Pond Science

Research, teaching, and mentorship in the sciences

Landscape Ecology 2.0

intersecting landscape ecology, open science, and R


The Research Blog of IIASA

Jörg Steinkamps Blog

Mainly things about R, Linux and vegetation modeling

Amy Whitehead's Research

the ecological musings of a conservation biologist

Michael McCarthy's Research

School of BioSciences, The University of Melbourne

The Rostrum

science, statistics, policy and more


Environmental Change - Understand, Predict, Adapt

Dynamic Ecology

Multa novit vulpes


METeorological Visualisation Utilities using R for Science and Teaching

A Birder´s Blog

"Everybody loves what they know"


A new metric to quantify biodiversity response to fragmentation

Trust Me, I'm a Geographer

Using Technology to Explore Our World

Duncan Golicher's weblog

Research, scripts and life in Chiapas

%d bloggers like this: