omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Math

    Pythonista
    4
    6
    1646
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • OkieWolf
      OkieWolf last edited by OkieWolf

      Why is it that when programming you have to convert angles to radians before any calculations?
      I created an Excel spreadsheet a while ago that holds quite a few engineering calculations (fairly simple) that I use a lot. In doing so, anywhere trig and angles are used I had to convert any angle in degrees to radians to get the answer to come out correctly.
      Then today I was creating a similar script in Pythonista and had to do the same thing.
      Is there any way to set everything to degrees globally?

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by ccc

        https://docs.python.org/3/library/math.html
        https://github.com/TheAlgorithms/Python/tree/master/maths

        1 Reply Last reply Reply Quote 0
        • OkieWolf
          OkieWolf last edited by OkieWolf

          I realize there is math.radians and math.degrees that does the same as radians = (degrees * 180)/pi and degrees = (radians * pi)/180.
          I also realize that some people say that radians are required for certain calculations. But I’ve worked in engineering for almost 30 years and have done thousands upon thousands of calculations and have never, not even once, had the need to calculate anything using radians. So why are radians so prevalent in coding especially?

          mikael 1 Reply Last reply Reply Quote 1
          • mikael
            mikael @OkieWolf last edited by mikael

            @OkieWolf, degrees are a ”human” measure based on a convention. The number 360 is completely arbitrary, even if it was decided on by ancient Babylonians and by now ”feels right” to most of us, myself included.

            There are other systems, for example dividing a quarter of a circle in 100 units instead of 90, but they are equally arbitrary, partly based on the fact that we have 10 fingers.

            Radians, on the other hand, are ”scientific”. They are an inherent property of a circle, since the angle of 1 radian corresponds to traveling the distance of the circle’s radius around the circle. Thus radians are radians whatever humans decide.

            1 Reply Last reply Reply Quote 2
            • JonB
              JonB last edited by JonB

              Radians are much more natural when computing sin/cos's.

              sin(x) = x - x**3/3! + x**5/5! - .... 
              

              So, small angles are easy to work with in radians, because sin(x) = x. Also, from a beauty perspective, sin and cosine are defined this way -- using any other unit results in ugly equations, which therefore are less fundamental.

              Consider other branches of physics/engineering where you deal with oscillators/wave equations. There you have sins/cos's of other unitless quantities, such as frequency times time, or distance divided by wavelength -- things get really clumsy if everything must be defined in degrees.

              Degrees really only ever make sense when talking about geometrical things, though arguably "revolutions" is a more fundamental / intuitive concept..

              1 Reply Last reply Reply Quote 1
              • JonB
                JonB last edited by

                Btw, you can of course define your own wrappers for sind/cosd (sin or cos in deg)!

                sind=lamda x:math.sin(math.radians(x))
                print(sind(90))
                
                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors