Re: [R] Calculating angle of a polyline

2018-01-30 Thread Eric Berger
nice On Tue, Jan 30, 2018 at 7:05 PM, William Dunlap wrote: > I like to use complex numbers for 2-dimensional geometry. E.g., > > > polyAngles2 > function (xV, yV) > { > stopifnot((length(xV) == length(yV)) && (length(xV) >= 3)) > z <- complex(re = xV, im = yV) > c(NA, diff(Arg(diff

Re: [R] Calculating angle of a polyline

2018-01-30 Thread William Dunlap via R-help
I like to use complex numbers for 2-dimensional geometry. E.g., > polyAngles2 function (xV, yV) { stopifnot((length(xV) == length(yV)) && (length(xV) >= 3)) z <- complex(re = xV, im = yV) c(NA, diff(Arg(diff(z))), NA) # radians, positive is counter-clockwise } > x <- c(0:3) > y <- c(0

Re: [R] Calculating angle of a polyline

2018-01-30 Thread Eric Berger
Assuming your polyline is defined by two vectors, one for the x coordinates, one for the y coordinates, you can try the following library(NISTunits) polyangles <- function(xV,yV) { stopifnot( (length(xV)==length(yV)) && (length(xV) >= 3)) v <- function(i) { c( xV[i]-xV[i-1], yV[i]-yV[i-1])}

Re: [R] Calculating angle of a polyline

2018-01-30 Thread Jeff Newmiller
A polyline by definition has many angles, so your question is ill-formed. And this is a question about math, not R, so is off topic here. I suggest reading Wikipedia. -- Sent from my phone. Please excuse my brevity. On January 29, 2018 11:10:02 PM PST, javad bayat wrote: >Dear R users >I am tr

[R] Calculating angle of a polyline

2018-01-30 Thread javad bayat
Dear R users I am trying to find a formula to calculate the angle of a polyline. Is there a way to do this? Many thanks. -- Best Regards Javad Bayat M.Sc. Environment Engineering Alternative Mail: bayat...@yahoo.com [[alternative HTML version deleted]] __