sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby get slope of a surface

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 417 Views 5 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.
    • O Offline
      ordoumpozanis
      last edited by

      Hi all,
      I am new to Ruby and I' like so help. I am trying to write a code that gives the slope (angle between the blue line and and the the face normal) of a roof but i cannot get it work

      I am using this code but does not work

      norm.angle_between
      slope = norm.angle_between(Geom::Vector3d.new(0,0,1)).radians

      any help ?

      thanks

      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        Hi, it's simple:
        "it doesn't work" = "it doesn't do what I expected"
        Then what do you expect?

        Your example worked with that face:

        face = Sketchup.active_model.entities.add_face(ORIGIN, [0,1,0],[1,1,1],[1,0,1]).reverse
        slope = face.normal.angle_between(Z_AXIS).radians
        >> 45.0
        

        Please make test cases (and define for each an expected result), then test each and then you either correct the code or the test case.

        1 Reply Last reply Reply Quote 0
        • O Offline
          ordoumpozanis
          last edited by

          Aerillus Thanks for the reply πŸ˜„

          If I understant well at the first line you design a surfae and at the second one you get the slope..

          when I am trying to apply the second commant
          slope = face.normal.angle_between(Z_AXIS).radians
          on a design face i get a nill value

          what do I make Wrong here ?

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            Give us the full code then, instead of the snippet you provided. If your code isn't working, then it might have something to do with how you are retrieving the face object. Are you sure you're actually referencing a face for example?

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

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

              Code and sample model.

              Whenever I get unexpected result I ensure I inspect the values of the variables I use - to make they they contain the values I expect them to be. Often the error can be in another place.

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

              1 Reply Last reply Reply Quote 0
              • O Offline
                ordoumpozanis
                last edited by

                The code that i am trying to apply to get the slope of a model's surfaces is the following

                <span class="syntaxdefault">&nbsp;&nbsp;model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />&nbsp;&nbsp;ss</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br />&nbsp;&nbsp;faces</span><span class="syntaxkeyword">=[];&nbsp;</span><span class="syntaxdefault">ss</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">faces&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">e&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.class==</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">}&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;</span><span class="syntaxdefault">faces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">|<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_s</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">";"</span><span class="syntaxkeyword">)[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">">"</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">norm</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br />&nbsp;&nbsp;&nbsp;&nbsp;slope&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Z_AXIS</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">radians<br />&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;slope<br />&nbsp;&nbsp;</span><span class="syntaxkeyword">}&nbsp;</span><span class="syntaxdefault"></span>
                

                ok i now i have program somthing wrong but i cannot find out what πŸ˜„

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

                  Can you also post a model with a face where the result is incorrect? (Please also describe what is expected value.)

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

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

                    Are you still using SketchUp 6 Pro ?

                    There was a bug in the Geom::Vector3d#angle_between() method that was fixed sometime in the 7.x branch.

                    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