       Re: Problem with finding angles between points in Cartesian plane

• To: mathgroup at smc.vnet.net
• Subject: [mg26113] Re: [mg26060] Problem with finding angles between points in Cartesian plane
• From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
• Date: Tue, 28 Nov 2000 01:56:00 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Here is another, essentially equivalent, approach which you may  like better
since it is more like your original attempt:

In:=
angle[P_, Q_] := ArcTan[(P - Q)[], (P - Q)[]]

In:=
angle[{3, 5}, {3, 4}]
Out=
Pi
--
2
In:=
angle[{3, 4}, {3, 5}]
Out=
Pi
-(--)
2

In:=
angle[{x1, y1}, {x1, y2}]

Out=
ArcTan[0, y1 - y2]

In:=
FullSimplify[%, y2 > y1]
General::"dbyz": "Division by zero."
Out=
Pi
-(--)
2
--
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/

on 00.11.22 8:29 PM, Andrzej Kozlowski at andrzej at tuins.ac.jp wrote:
> When I saw your question I could not  understand what you meant by the "angle
> between two points"? There is really no such thing. At first I assumed you
> meant the angle between the two vectors corresponding to  two points, but
> looking at your formula I realized that you seemed to mean the angle that the
> line through the two points makes with the x-axis (?).
>
> Well, here is one (out of very many) ways that will compute this without
>
> angle[P_, Q_] := Arg[(Q - P).{1, I}]
>
> Now we get:
>
> In:=
> angle[{3, 4}, {3, 5}]
>
> Out=
> Pi/2
>
> However, this angle actually depend on the order in which the points are
> given:
>
> In:=
> angle[{3, 5}, {3, 4}]
>
> Out=
> -(Pi/2)
>
> If you prefer the answer not to depend on the order of the points you can do
> this:
>
> ClearAll[angle]
>
> SetAttributes[angle, Orderless]
>
> angle[P_, Q_] := Arg[(Q - P).{1, I}]
>
>
> Now we get:
>
> In:=
> angle[{3, 5}, {3, 4}]
>
> Out=
> Pi/2
>
> In:=
> angle[{3, 4}, {3, 5}]
>
> Out=
> Pi/2
>
>
> Another possible objection may be that this does definition of angle does not
> work with symbolic expressions, in other words with your original example we
> get:
>
> In:=
> angle[{x1, y1}, {x1, y2}]
>
> Out=
> Arg[I*(-y1 + y2)]
>
> This however is really the way it should be since Mathematica know nothing
> about y1 and y2 (they might be equal or complex !). In such cases its best to
> apply FullSimplify:
>
> In:=
> FullSimplify[%, y2 > y1]
>
> Out=
> Pi/2
>
> --
> Andrzej Kozlowski
> Toyama International University
> JAPAN
>
> http://platon.c.u-tokyo.ac.jp/andrzej/
> http://sigma.tuins.ac.jp/
>
>
> on 00.11.22 3:55 PM, Blitzer at drek1976 at yahoo.com wrote:
>
>> I would like to find the angle between 2 points on the Cartesian plane.
>> However, if I use "ArcTan", it is not able to recognise that points with the
>> same x-coordinates have an angle of 90 degrees between them. It returns
>> "Indeterminate".
>> eg. for a point A (x1, y1) and a point (x1, y2), to find the angle between
>> them, I use ArcTan[(y2-y1)/(x1-x1)]. However, as the denominator is equal to
>> "0", this function returns "indeterminate". Is there a way to get around
>> this problem? Or is there other possible functions which can be used.
>> I am dealing with a very large array of numbers and thus, it's not possible
>> to check the coordinates individually.
>>
>> Would be grateful for any help rendered. Thanks!
>>
>> Derek
>>
>>
>>
>>
>>
>

```

• Prev by Date: Re: Problem with finding angles between points in Cartesian plane
• Next by Date: Re: PageWidth mystery
• Previous by thread: Re: Problem with finding angles between points in Cartesian plane
• Next by thread: question RE: difference equations