ATAN2(y,x) for dynamic components
-
I would like to make a formal request for either an Arg(x,y) or Atan2(y,x) to be part of the built in functions for dynamic components.
It makes life easier when you know what your angles are (positive or negative).
-
Drop this in your plugins folder...
class DCFunctionsV1 protected def atan2(*a) return Math;;atan2(a[0], a[1]) end end
Of course, all of your DC users will also need this installed...
And... who knows what will happen if Google does decides to implement it someday.
-
@jim said:
Of course, all of your DC users will also need this installed...
Exactly why I want it as part of Sketchup itself...
Shrugs Oh well, thanks for the code. I'll probably end up using it as well.
-
@jim said:
Drop this in your plugins folder...
class DCFunctionsV1 > protected > def atan2(a) > return Math;;atan2(a[0], a[1]) > end > end >
Of course, all of your DC users will also need this installed...
And... who knows what will happen if Google does decides to implement it someday.
Lemme do a quick fix on that...
class DCFunctionsV1 protected def atan2(a) return Math;;atan2(a[0], a[1]).radians end end
sighs half an hour wasted...
-
@markozeta said:
@jim said:
Drop this in your plugins folder...
class DCFunctionsV1 > > protected > > def atan2(*a) > > return Math;;atan2(a[0], a[1]) > > end > > end > >
Lemme do a quick fix on that...
class DCFunctionsV1 > protected > def atan2(a) > return Math;;atan2(a[0], a[1]).radians > end > end >
You are correct for the argument, in that the DC extension always passes the function arguments as an Array (so the ***** expansion operator is not needed.)
However, all the other trig functions do not have built-in radians to degrees conversion, and to follow convention, the internal code for the function should be as Jim showed.
If you wish degrees from a result that returns radians, you should use the DC function
degrees( *radian_arg* )
, as in:degrees( atan2(n1,n2) )
require('dynamiccomponents.rb') if defined?($dc_observers) # only if DC extension is active class DCFunctionsV1 protected def atan2(a) return Math;;atan2(a[0], a[1]) end #def end #class end #if
NOTE: modifying this class no longer makes it version 1
-
See also this topic in Developers Forum:
Custom Dynamic Component Functions = Ruby links -
Experimentation indicates that function arguments are passed to the Ruby method as an array of strings. So, it seems like the Ruby method should be performing coercion on the input values. (eg, a[0].to_f). Am I missing something?
-r
-
@richmorin said:
Experimentation indicates that function arguments are passed to the Ruby method as an array of strings.
Well, obviously the entire formula begins as one big lengthy string, is repeatedly parsed and broken up into smaller and smaller tokens, until it can build it's param arrays to pass to internal DC functions.
However it's not always necessary internally (DC parsing) for the params to be passed as string representations, to the DC formula method(s), if it was already necessary for the DC parser to convert the sub-string operands to aNumeric
(for say, some logical comparison, in order to make a code branching decision.)@richmorin said:
So, it seems like the Ruby method should be performing coercion on the input values. (eg,
a[0].to_f
).
Exactly what they all of the mathematical DC functions do internally, just to be safe, before passing any values to methods in theMath
module (or otherwise where aNumeric
type is expected.)IF you just have to modify the
DCFunctionsV1
class, for your own use, it would only be smart, to also do.to_f()
coercion.@richmorin said:
Am I missing something?
Only that there are some DC functions that specifically use string args. (But we can ignore this for this issue...)
Advertisement