Math.atan()

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

  1. Numeron

    Numeron Guest

    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
     
    Numeron, Oct 27, 2008
    #1
    1. Advertising

  2. 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
    > 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
     
    Patricia Shanahan, Oct 27, 2008
    #2
    1. Advertising

  3. 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
    > 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>
     
    Jussi Piitulainen, Oct 27, 2008
    #3
  4. 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.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).
     
    Andreas Leitgeb, Oct 27, 2008
    #4
  5. Numeron

    Stefan Ram Guest

    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
    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)
     
    Stefan Ram, Oct 27, 2008
    #5
  6. 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>
    <http://en.wikipedia.org/wiki/Radian>

    [...]
    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
     
    John B. Matthews, Oct 27, 2008
    #6
  7. 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.toRadians(Math.atan(1.0))

    >
    > 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
    #7
  8. 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
    > 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)


    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
     
    John B. Matthews, Oct 27, 2008
    #8
  9. Numeron

    Roedy Green Guest

    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.
    --
    Roedy Green Canadian Mind Products
    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.
     
    Roedy Green, Oct 27, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andi

    atan in a FPGA

    Andi, Sep 23, 2003, in forum: VHDL
    Replies:
    2
    Views:
    2,810
    Acciduzzu
    Sep 25, 2003
  2. chirs
    Replies:
    18
    Views:
    798
    Chris Uppal
    Mar 2, 2004
  3. Mr. Ken
    Replies:
    5
    Views:
    740
  4. harryos
    Replies:
    15
    Views:
    2,263
    Dr J R Stockton
    Dec 10, 2009
  5. VK
    Replies:
    15
    Views:
    1,312
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page