Was Yukihiro Matsumoto interested in Math?
-
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.
- no cube root function
- no sin function
- no cos function
- 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!

-
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-tanAs for 1: a simple Google search found this thread with lots of example methods for cube root: http://www.ruby-forum.com/topic/191287
-
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 easyx**(1/3.0)returns the cuberoot of 'x' - so if x=27 you get 3.0 as the answer...

-
In addition to the standard functions that are always loaded into the
Mathmodule, you can load the extended functions into theMathmodule, byrequire'ing the library extension 'mathn.rb', ie:with a path to a full Ruby install's lib directory in the
$LOAD_PATHarray:
require('mathn.rb')This math extension, in turn, loads:
'complex.rb'
'rational.rb'
'matrix.rb'Once loaded... there are many more functions, including
sqrt()andrsqrt(), arc and hyperbolic functions. It also creates some newNumericclasses, such asPrime,RationalandComplex, and adds a few methods to existing classes, such asInteger.Refer to docs on:
-
Thank you gentlemen: much appreciated, and I promise not to do math past my bedtime again. (Unless I forget!)

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement