[R] Function to find angle between coordinates?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 1 17:07:27 CEST 2009


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.
>




More information about the R-help mailing list