Math.atan()

N

Numeron

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
Math.atan(Math.toRadians(1.0)) = 0.0175
(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
 
P

Patricia Shanahan

Numeron said:
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
Math.atan(Math.toRadians(1.0)) = 0.0175
(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.

Math.toRadians(Math.atan(1.0))

Patricia
 
J

Jussi Piitulainen

Eric said:
Right. And it does. You've mis-read or misunderstood
the Javadoc: Math.atan() takes a ratio and yields radians.

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

Andreas Leitgeb

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

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

Stefan Ram

Patricia Shanahan said:
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
measured in radiants.

But I can not find »arcus cuius tangens est« in the Web, so my
memory about this phrase might be wrong.

(»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)
 
J

John B. Matthews

Numeron said:
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>
<http://en.wikipedia.org/wiki/Radian>

[...]
 
P

Patricia Shanahan

Andreas said:
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
 
J

John B. Matthews

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
measured in radiants.

But I can not find »arcus cuius tangens est« in the Web, so my
memory about this phrase might be wrong.

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
t having radius=1]:

<http://books.google.com/books?id=7juWmvQSTvwC&pg=RA1-PA175&lpg=RA1-PA175
&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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top