none
Turtle angle returns number greater than 360 and less than 0 (zero). RRS feed

  • Question

  • I think I found my problem.
    I thought the turtle angle would be based off of 360 degrees, but it looks like I am wrong.

    One Turtle.Angle returned "1788" and another was "-1005"
    So I guess I don't know how the turtle angle works.

    Can anyone explain what numbers the Turtle.Angle is based on and is there an upper and lower limit?
    Wednesday, February 18, 2009 7:51 PM

Answers

  • "divided by 360 and the remainder taken"

    Using Small Basic, it would Math.Remainder(dividend, divisor)

    'One Turtle.Angle returned "1788" and another was "-1005"

    angle = Math.Remainder(1788, 360)
    TextWindow.WriteLine(angle)
    angle = Math.Remainder(-1005, 360)
    TextWindow.WriteLine(angle)

    output:

    348
    -285

    • Marked as answer by Path_drc Wednesday, February 18, 2009 9:23 PM
    Wednesday, February 18, 2009 8:44 PM
  • The angles around a circle obey what is sometimes called "Clock Arithmetic". The numbers of a clock go from 1 to 12 and back to 1 again. If you have 8 hours and add 7 hours you get 15 hours, but this doesn't appear on a clock face. Instead you take 4 hours to get to 12 and the remaining 3 takes you to 3 hours.
    Think back to when you learnt to divide at school. Before you learnt about decimals, you would say, for example, that 3 goes into 11, 3 times, remainder 2. With angles, we are not interested in how many whole lots of 360 degrees we have, as they just bring us back the way we were originally facing. We are interested in the remainder.
    Dividing the Turtle.Angle by 360 gives us the whole number of rotations (the integer part, to the left of the decimal point) which we are not interested in and the remainder as a fraction of 360 as the decimal part. We need this decimal part but without it being divided by 360. Fortunately there is a function which gives us the remainder
    Math.Remainder

    Try,

    Turtle.Angle = 370
    TextWindow.WriteLine(math.Floor(Turtle.Angle/360))
    TextWindow.WriteLine(Math.Remainder(Turtle.Angle, 360))

    The output from this is,
    1
    10
    Press any key to continue...

    You will see that the last line gives the correct result.

    P.S.
    You do not need to worry about taking the remainder (unless you want to display the angle) as that is done for you by Turtle.Angle
    • Edited by Stendec Wednesday, February 18, 2009 8:58 PM P.S. Added
    • Marked as answer by Path_drc Wednesday, February 18, 2009 9:23 PM
    Wednesday, February 18, 2009 8:52 PM

All replies

  • See Vijaye's answer to the thread "Turtle.Angle is this a Bug or a Feature". The value is not constrained but modded with 360 (divided by 360 and the remainder taken) when it is used.
    • Marked as answer by Path_drc Wednesday, February 18, 2009 8:09 PM
    • Unmarked as answer by Path_drc Wednesday, February 18, 2009 8:24 PM
    Wednesday, February 18, 2009 8:03 PM
  • ...and I thought I read every thread in the Small Basic forum.

    Thanks for the info!
    Wednesday, February 18, 2009 8:09 PM
  • Stendec; 

    Well he basically said what you said, though you said a little bit more, but I am still not able to figure out the correct angle.

    Based on your statement ("divided by 360 and the remainder taken"), should this line of code return the proper number in 360 degree format?

    TextWindow.WriteLine(math.Floor(Turtle.Angle/360))

    Please forgive my ignorance.

    THNX!
    Wednesday, February 18, 2009 8:28 PM
  • "divided by 360 and the remainder taken"

    Using Small Basic, it would Math.Remainder(dividend, divisor)

    'One Turtle.Angle returned "1788" and another was "-1005"

    angle = Math.Remainder(1788, 360)
    TextWindow.WriteLine(angle)
    angle = Math.Remainder(-1005, 360)
    TextWindow.WriteLine(angle)

    output:

    348
    -285

    • Marked as answer by Path_drc Wednesday, February 18, 2009 9:23 PM
    Wednesday, February 18, 2009 8:44 PM
  • The angles around a circle obey what is sometimes called "Clock Arithmetic". The numbers of a clock go from 1 to 12 and back to 1 again. If you have 8 hours and add 7 hours you get 15 hours, but this doesn't appear on a clock face. Instead you take 4 hours to get to 12 and the remaining 3 takes you to 3 hours.
    Think back to when you learnt to divide at school. Before you learnt about decimals, you would say, for example, that 3 goes into 11, 3 times, remainder 2. With angles, we are not interested in how many whole lots of 360 degrees we have, as they just bring us back the way we were originally facing. We are interested in the remainder.
    Dividing the Turtle.Angle by 360 gives us the whole number of rotations (the integer part, to the left of the decimal point) which we are not interested in and the remainder as a fraction of 360 as the decimal part. We need this decimal part but without it being divided by 360. Fortunately there is a function which gives us the remainder
    Math.Remainder

    Try,

    Turtle.Angle = 370
    TextWindow.WriteLine(math.Floor(Turtle.Angle/360))
    TextWindow.WriteLine(Math.Remainder(Turtle.Angle, 360))

    The output from this is,
    1
    10
    Press any key to continue...

    You will see that the last line gives the correct result.

    P.S.
    You do not need to worry about taking the remainder (unless you want to display the angle) as that is done for you by Turtle.Angle
    • Edited by Stendec Wednesday, February 18, 2009 8:58 PM P.S. Added
    • Marked as answer by Path_drc Wednesday, February 18, 2009 9:23 PM
    Wednesday, February 18, 2009 8:52 PM
  •   Thank you Rushworks for your clear and to the point answer.
    I know what MathRemainder does so now I know what Stendec was talking about.

    Thank you Stendec for expanding my mind with the details.
    Wednesday, February 18, 2009 9:23 PM