python math problem

Discussion in 'Python' started by Kene Meniru, Feb 15, 2013.

  1. Kene Meniru

    Kene Meniru Guest

    I am trying to calculate the coordinates at the end of a line. The length
    and angle of the line are given and I am using the following formula:

    x = (math.sin(math.radians(angle)) * length)
    y = (math.cos(math.radians(angle)) * length)

    The following are sample answers in the format (x, y) to the given
    length/angle values of the line:

    120/0 = (0.0, 25.0)
    120/89 = (24.9961923789, 0.436310160932)
    120/90 = (25.0, 1.53075794228e-15)
    120/91 = (24.9961923789, -0.436310160932)

    Why am I getting a string number instead of the expected answer for 120/90
    which should be (25.0, 0.0). This happens at all multiples of 90 (i.e. 180
    and 270)

    --

    Kene
    ::::::::::::::::::
     
    Kene Meniru, Feb 15, 2013
    #1
    1. Advertising

  2. Kene Meniru

    John Machin Guest

    On Feb 16, 6:39 am, Kene Meniru <> wrote:

    > x = (math.sin(math.radians(angle)) * length)
    > y = (math.cos(math.radians(angle)) * length)


    A suggestion about coding style:

    from math import sin, cos, radians # etc etc
    x = sin(radians(angle)) * length
    y = cos(radians(angle)) * length

    .... easier to write, easier to read.
     
    John Machin, Feb 16, 2013
    #2
    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. chirs
    Replies:
    18
    Views:
    776
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,113
    Jonathan Turkanis
    Apr 1, 2004
  3. Mark Healey
    Replies:
    7
    Views:
    1,490
    Tim Prince
    May 22, 2006
  4. Philipp
    Replies:
    9
    Views:
    1,132
    Mark Space
    Jul 23, 2008
  5. VK
    Replies:
    15
    Views:
    1,179
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page