Math.atan()

Discussion in 'Java' started by Numeron, Oct 27, 2008.

1. NumeronGuest

I have a problem trying to find the angle between two lines using
their slopes. I know that the angle is defined as the difference
between the arctan(slope)'s for each line, but java's Math.atan()
takes radians which confuses me, because the inverse of a tangent
function should *output* radians (or degrees) and just take a number
right?

As an easy example the arctan of the slope 1.0 should equal 45 degrees
but
Math.atan(1.0) = 0.7854
(not that attempting to convert a slope to radians makes sense anyway)

So how can I bend Math.atan() to work the way Im after?

-Numeron

Numeron, Oct 27, 2008

2. Patricia ShanahanGuest

Numeron wrote:
> I have a problem trying to find the angle between two lines using
> their slopes. I know that the angle is defined as the difference
> between the arctan(slope)'s for each line, but java's Math.atan()
> takes radians which confuses me, because the inverse of a tangent
> function should *output* radians (or degrees) and just take a number
> right?
>
> As an easy example the arctan of the slope 1.0 should equal 45 degrees
> but
> Math.atan(1.0) = 0.7854
> (not that attempting to convert a slope to radians makes sense anyway)
>
> So how can I bend Math.atan() to work the way Im after?

Math.atan does indeed take a number, and return an angle in radians.
0.7854 radians is, to four significant digits, 45 degrees.

Patricia

Patricia Shanahan, Oct 27, 2008

3. Jussi PiitulainenGuest

Eric Sosman writes:
> Numeron wrote:
> > I have a problem trying to find the angle between two lines using
> > their slopes. I know that the angle is defined as the difference
> > between the arctan(slope)'s for each line, but java's Math.atan()
> > takes radians which confuses me, because the inverse of a tangent
> > function should *output* radians (or degrees) and just take a
> > number right?

>
> Right. And it does. You've mis-read or misunderstood

Javadoc used to be so easy to mis-read on this point that one might
even say it had been mis-written. It is changed now. Here are the two
different versions:

static double atan(double a) Returns the arc tangent of an angle, in
the range of -pi/2 through pi/2.

static double atan(double a) Returns the arc tangent of a value; the
returned angle is in the range -pi/2 through pi/2.

<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html>
<http://java.sun.com/javase/6/docs/api/java/lang/Math.html>

Jussi Piitulainen, Oct 27, 2008
4. Andreas LeitgebGuest

Patricia Shanahan <> wrote:
>> So how can I bend Math.atan() to work the way Im after?

> Math.atan does indeed take a number, and return an angle in radians.
> 0.7854 radians is, to four significant digits, 45 degrees.

Math.toDegrees(Math.atan(1.0)) of course.

By the way, there is also Math.atan2(double x, double y),
which - unlike the typical use Math.atan(y/x) - also deals
properly (and numerically stable) with infinitely or almost
infinitely sloped lines (in the vicinity of 90 or 270 degrees).

Andreas Leitgeb, Oct 27, 2008
5. Stefan RamGuest

Patricia Shanahan <> writes:
>Math.atan does indeed take a number, and return an angle in radians.

I used to believe that this was already implied by the name of
that function, because I used to believe that »atan( x )«
means »arcus cuius tangens est x«, which indicates that »x« is
a tangent (ratio) and the result is an arcus (»bow«), which is

But I can not find »arcus cuius tangens est« in the Web, so my

(»Tangent was introduced by Thomas Fincke (1561-1656) in his
Thomae Finkii Flenspurgensis Geometriae rotundi libri XIIII,
Basileae: Per Sebastianum Henricpetri, 1583. He wrote "tangens"
in Latin.« - http://jeff560.tripod.com/t.html)

(»"Arctangent" appears in Hedrick [1904]« -
http://jeff560.tripod.com/a.html)

Stefan Ram, Oct 27, 2008
6. John B. MatthewsGuest

In article
<>,
Numeron <> wrote:

> I have a problem trying to find the angle between two lines using
> their slopes.

You might elaborate on the problem you're trying to solve. There may be
some simplification inherent in the problem itself. For example, this
model of two-dimensional elastic collisions uses just vector arithmetic:

<http://www.geocities.com/vobarian/2dcollisions>

[...]
> As an easy example the arctan of the slope 1.0 should equal 45 degrees.

That's the same as pi/4 radians.

[...]
> (not that attempting to convert a slope to radians makes sense anyway)

You might want to revisit the relationship between slope and angle:

<http://en.wikipedia.org/wiki/Slope>

[...]
--
John B. Matthews
trashgod at gmail dot com

John B. Matthews, Oct 27, 2008
7. Patricia ShanahanGuest

Andreas Leitgeb wrote:
> Patricia Shanahan <> wrote:
>>> So how can I bend Math.atan() to work the way Im after?

>
>> Math.atan does indeed take a number, and return an angle in radians.
>> 0.7854 radians is, to four significant digits, 45 degrees.

>
> Math.toDegrees(Math.atan(1.0)) of course.

Of course. Sorry about the error.

>
> By the way, there is also Math.atan2(double x, double y),
> which - unlike the typical use Math.atan(y/x) - also deals
> properly (and numerically stable) with infinitely or almost
> infinitely sloped lines (in the vicinity of 90 or 270 degrees).
>

Yes, generally Math.atan2 is better, if you know both x and y.

Patricia

Patricia Shanahan, Oct 27, 2008
8. John B. MatthewsGuest

In article <-berlin.de>,
-berlin.de (Stefan Ram) wrote:

> Patricia Shanahan <> writes:
> >Math.atan does indeed take a number, and return an angle in radians.

>
> I used to believe that this was already implied by the name of
> that function, because I used to believe that »atan( x )«
> means »arcus cuius tangens est x«, which indicates that »x« is
> a tangent (ratio) and the result is an arcus (»bow«), which is
>
> But I can not find »arcus cuius tangens est« in the Web, so my

I believe you are correct. In _A History_of_Mathematical_Notations_,
Florian Cajori indicates that Euler used the phrase, "expresio A t nobis
denotet arcum circuli, cuius tangens est t existente radio=1," ca. 1736.
[The expression A t denotes to us the arc of a circle, which is touching

&dq=arcus+cuius+tangens+est&source=bl&ots=KWeqAeH7Nr&sig=kFgGnr-PSFOo1Fyp
XnSiaIaPYyo&hl=en&sa=X&oi=book_result&resnum=1&ct=result>

> (»Tangent was introduced by Thomas Fincke (1561-1656) in his
> Thomae Finkii Flenspurgensis Geometriae rotundi libri XIIII,
> Basileae: Per Sebastianum Henricpetri, 1583. He wrote "tangens"
> in Latin.« - http://jeff560.tripod.com/t.html)
>
> (»"Arctangent" appears in Hedrick [1904]« -
> http://jeff560.tripod.com/a.html)

--
John B. Matthews
trashgod at gmail dot com

John B. Matthews, Oct 27, 2008
9. Roedy GreenGuest

On Sun, 26 Oct 2008 19:31:08 -0700 (PDT), Numeron
<> wrote, quoted or indirectly
quoted someone who said :

>but java's Math.atan()
>takes radians which confuses me, because the inverse of a tangent
>function should *output* radians (or degrees) and just take a number
>right?

see http://mindprod.com/jgloss/trigonometry.html
tan takes radians and produces a double.
atan takes a double and produces radians, which you can then convert
to degrees.
--