sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Was Yukihiro Matsumoto interested in Math?

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 1.0k Views 4 Watching
    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.
    • T Offline
      tomot
      last edited by

      I ask that question in light of the fact that there are very few basic math methods available in Ruby, related to the attached pic.

      1. no cube root function
      2. no sin function
      3. no cos function
      4. no tan function

      Is anyone with superior ruby skills able to create these 4 functions for use within the SketchUp Ruby API ? I would be grateful!


      3060right.jpg

      [my plugins](http://thingsvirtual.blogspot.ca/)
      tomot

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        2: http://ruby-doc.org/core-1.8.6/Math.html#method-c-sin
        3: http://ruby-doc.org/core-1.8.6/Math.html#method-c-cos
        4: http://ruby-doc.org/core-1.8.6/Math.html#method-c-tan

        As for 1: a simple Google search found this thread with lots of example methods for cube root: http://www.ruby-forum.com/topic/191287

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          For question 1) it's actually the 'squareroot of three' not a 'cuberoot', so this applies http://ruby-doc.org/core-1.8.6/Math.html#method-c-sqrt
          Math.sqrt(3)
          returns
          1.73205080756888
          As tt says, there are a range of Math tools available, and making the 'missing ones' like your own cube-root [or any root] method is very easy x**(1/3.0) returns the cuberoot of 'x' - so if x=27 you get 3.0 as the answer...
          πŸ€“

          TIG

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            In addition to the standard functions that are always loaded into the Math module, you can load the extended functions into the Math module, by require'ing the library extension 'mathn.rb', ie:

            with a path to a full Ruby install's lib directory in the $LOAD_PATH array:
            require('mathn.rb')

            This math extension, in turn, loads:
            'complex.rb'
            'rational.rb'
            'matrix.rb'

            Once loaded... there are many more functions, including sqrt() and rsqrt(), arc and hyperbolic functions. It also creates some new Numeric classes, such as Prime, Rational and Complex, and adds a few methods to existing classes, such as Integer.

            Refer to docs on:

            • mathn
            • complex
            • matrix

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomot
              last edited by

              Thank you gentlemen: much appreciated, and I promise not to do math past my bedtime again. (Unless I forget!) 😳

              [my plugins](http://thingsvirtual.blogspot.ca/)
              tomot

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement