sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    ATAN2(y,x) for dynamic components

    Scheduled Pinned Locked Moved SketchUp Feature Requests
    sketchup
    8 Posts 4 Posters 10.6k 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.
    • M Offline
      markozeta
      last edited by

      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).

      BSME - Cal Poly Pomona
      Sketchup Pipe Maniac

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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.

        Hi

        1 Reply Last reply Reply Quote 0
        • M Offline
          markozeta
          last edited by

          @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.

          BSME - Cal Poly Pomona
          Sketchup Pipe Maniac

          1 Reply Last reply Reply Quote 0
          • M Offline
            markozeta
            last edited by

            @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...

            BSME - Cal Poly Pomona
            Sketchup Pipe Maniac

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

              @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

              I'm not here much anymore.

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

                See also this topic in Developers Forum:
                Custom Dynamic Component Functions = Ruby links

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • RichMorinR Offline
                  RichMorin
                  last edited by

                  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

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

                    @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 a Numeric (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 the Math module (or otherwise where a Numeric 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...)

                    I'm not here much anymore.

                    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