Velocity Reviews > Java > Math.atan()

# Math.atan()

Numeron
Guest
Posts: n/a

 10-27-2008
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

Patricia Shanahan
Guest
Posts: n/a

 10-27-2008
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

Jussi Piitulainen
Guest
Posts: n/a

 10-27-2008
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>

Andreas Leitgeb
Guest
Posts: n/a

 10-27-2008
Patricia Shanahan <(E-Mail Removed)> 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).

Stefan Ram
Guest
Posts: n/a

 10-27-2008
Patricia Shanahan <(E-Mail Removed)> 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)

John B. Matthews
Guest
Posts: n/a

 10-27-2008
In article
<(E-Mail Removed)>,
Numeron <(E-Mail Removed)> 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

Patricia Shanahan
Guest
Posts: n/a

 10-27-2008
Andreas Leitgeb wrote:
> Patricia Shanahan <(E-Mail Removed)> 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

John B. Matthews
Guest
Posts: n/a

 10-27-2008
In article <(E-Mail Removed)-berlin.de>,
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) wrote:

> Patricia Shanahan <(E-Mail Removed)> 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=KWeqAeH7 Nr&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

Roedy Green
Guest
Posts: n/a

 10-27-2008
On Sun, 26 Oct 2008 19:31:08 -0700 (PDT), Numeron
<(E-Mail Removed)> 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.
--
http://mindprod.com
The Canadian national animal should be changed from the beaver to the ostrich.
Canadians elected a party that denies global warming so they too could pretend it presents no danger.