clair.crossupton at googlemail.com
2009-Sep-01 13:08 UTC
[R] Function to find angle between coordinates?
Dear all, I was doing some self study and was wondering if a function already exists which allows one to determine the angle between points. e.g. given the following (x,y) coordinates input: (0,1); (0,0); (1,0) would result in: output: 90 degrees Best regards C.C.
Since the inner product of two vectors if the cos of the angle between them:> A <- c(0,1); O <- c(0,0); B <- c(1,0) > acos((A-O) %*% (B-O)) * 180 / pi[,1] [1,] 90 On Tue, Sep 1, 2009 at 9:08 AM, clair.crossupton at googlemail.com<clair.crossupton at googlemail.com> wrote:> Dear all, > > I was doing some self study and was wondering if a function already > exists which allows one to determine the angle between points. ?e.g. > given the following (x,y) coordinates > > input: (0,1); (0,0); (1,0) > > would result in: > > output: 90 degrees > > Best regards > C.C.
That is if they have length 1 as is the case here. Normalize them to length 1, if not. On Tue, Sep 1, 2009 at 11:06 AM, Gabor Grothendieck<ggrothendieck at gmail.com> wrote:> Since the inner product of two vectors if the cos of the > angle between them: > >> A <- c(0,1); O <- c(0,0); B <- c(1,0) >> acos((A-O) %*% (B-O)) * 180 / pi > ? ? [,1] > [1,] ? 90 > > > On Tue, Sep 1, 2009 at 9:08 AM, > clair.crossupton at googlemail.com<clair.crossupton at googlemail.com> > wrote: >> Dear all, >> >> I was doing some self study and was wondering if a function already >> exists which allows one to determine the angle between points. ?e.g. >> given the following (x,y) coordinates >> >> input: (0,1); (0,0); (1,0) >> >> would result in: >> >> output: 90 degrees >> >> Best regards >> C.C. >
?atan2 is a possible starting point. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of clair.crossupton at googlemail.com Sent: Tuesday, September 01, 2009 8:09 AM To: r-help at r-project.org Subject: [R] Function to find angle between coordinates? Dear all, I was doing some self study and was wondering if a function already exists which allows one to determine the angle between points. e.g. given the following (x,y) coordinates input: (0,1); (0,0); (1,0) would result in: output: 90 degrees Best regards C.C. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
clair.crossupton at googlemail.com
2009-Sep-01 16:28 UTC
[R] Function to find angle between coordinates?
Thank you very much, these were exactly what i needed! :-) C.C. On 1 Sep, 14:08, "clair.crossup... at googlemail.com" <clair.crossup... at googlemail.com> wrote:> Dear all, > > I was doing some self study and was wondering if a function already > exists which allows one to determine the angle between points. ?e.g. > given the following (x,y) coordinates > > input: (0,1); (0,0); (1,0) > > would result in: > > output: 90 degrees > > Best regards > C.C. > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.