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

    How do you detect a Polygon?

    Scheduled Pinned Locked Moved Developers' Forum
    31 Posts 7 Posters 1.5k Views 7 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.
    • thomthomT Offline
      thomthom
      last edited by

      @jim said:

      Can't just check if 2 adjacent edges are soft? Circles are, polys are not, right?

      Guess not.

      You'd think so, so did I and TIG, but that's not the case. πŸ˜•

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

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

        @thomthom said:

        @jim said:

        Can't just check if 2 adjacent edges are soft? Circles are, polys are not, right?

        Guess not.

        You'd think so, so did I and TIG, but that's not the case. πŸ˜•

        Thinking of it - it makes sense that they don't as that would render extruded circles invisible.

        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

          The Edges in a Curve that's an ArcCurve, that's either a Circle and a Polygon, are identical [neither are smooth nor soft] !!! It's only when you Extrude them in 3D the difference is visually [and Ruby-test-ably] apparent. There is [seems to be?] no Ruby-accessible Method to see if a looped ArcCurve is a Circle or a Polygon... UNLESS you do my elaborate lateral and clunky test by extruding it and testing the extrusion's edges for smooth/soft? ...

          TIG

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

            Another oddity. Select an extruded circle. From the console: sel[0].soft=true If you click on the circle where one of the edges now are soft - the circle is now selected as well as the faces connected to it.

            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

              @thomthom said:

              @thomthom said:

              @jim said:

              Can't just check if 2 adjacent edges are soft? Circles are, polys are not, right?

              Guess not.

              You'd think so, so did I and TIG, but that's not the case. πŸ˜•

              Thinking of it - it makes sense that they don't as that would render extruded circles invisible.

              Smooth/soft edges that are profiles stay visible...

              TIG

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

                Right, it's the connecting edges of an extrusion that are softened, not the perimeter of the polygon/circle.

                Hi

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

                  Only the edges that forms the outline of the geometry from the current view.

                  Look at it from an angle where it doesn't take part of the outline and it's hidden.


                  circle_soft.PNG

                  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

                    When you Smooth/Soften the Polygon's Edge its Face merges with the already Smoothed/Softened side Faces in the extrusion to give a single 'Surface' - as reported in the Entity Info Box. This 'Surface' Selects and Highlights as one thing... unless Hidden Geometry is 'on', then the separate Faces that make up that 'Surface' are individually Selectable/Highlighted. Presumably the [assumed] Face::is_surface? method that Entity Info uses, simply looks to see if some of the Face's Edges are Smooth/Soft and have extra Faces attached ?

                    TIG

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

                      I added a feature request on this topic.

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

                      1 Reply Last reply Reply Quote 0
                      • snicoloS Offline
                        snicolo
                        last edited by

                        Ok,
                        a quick and dirty way is to use

                        Sketchup.active_model.selection.count

                        if it returns 24 (default segments' number in a circle) it is a circle

                        if it returns anything else it is a polygon

                        This way does not work if you have 24 segments polygons or if you have changed the circle default segments number.

                        I am still trying to figure out a better way. πŸ˜‰

                        Simone Nicolo
                        QA Manager
                        http://www.sketchup.com

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

                          Circles can be converted to Polygons - so that won't do either. Detecting circle is easy - checking the start and end angle if it's 360degrees or more. (SU weirdness - circles some times comes out with an total angle of 720 degrees...)

                          Personally I often change the default segment count. And I also get lots of circles from DWGs.

                          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

                            My new method ArcCurve.is_loop? tells you if it's an open ended Arc, or looped as a Polygon or Circle, ==no_loose_ends.
                            The other methods ArcCurve.is_circle? and ArcCurve.is_polygon? return true if it is...
                            A clunky fix but it works...

                            TIG

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

                              FYI: the Google response to this:

                              @unknownuser said:

                              Hi Thomas,

                              I’ve traced this through the code, and I’m sad to report that there is nothing exposed in the API that allows you to (quickly) tell the difference between circles and polys. Internally, we store a flag so that says which tool created the curve object. I’ve logged a feature request to expose this in the API.

                              Until then, the only thing I can suggest is to make a hidden copy of the curve, extrude it, then see if the edges of the resulting faces are smooth. I haven’t tried this yet to see if it works successfully though.

                              Matt

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

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

                                FYI: since SU 7.1M1 you can detect polygons using Curve.is_polygon?

                                TIG: that code snippet of yours will now conflict with the new API method.

                                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

                                  @thomthom said:

                                  FYI: since SU 7.1M1 you can detect polygons using Curve.is_polygon?

                                  TIG: that code snippet of yours will now conflict with the new API method.

                                  I know BUT not pre v7.1M1... using needing to detect a Polygon need both - with aversion test to load ?

                                  TIG

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

                                    I use this: Sketchup::Curve.method_defined?(:is_polygon?)

                                    But this is why I prefer not to extend the native classes. If someone has implemented the old code - it will still conflict unless that code is updated.

                                    Instead I make methods where I also send the object I want to test. def MyLib.is_polygon?(curve) Completely future-safe.

                                    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

                                      Here's my three methods
                                      (I've improved .is_loop? to trap any of the arc's vertices that have other edges that are not forming part of that arc !)...

                                      ArcCurve.is_loop? returns true=Circle or Polygon: false=Arc
                                      ArcCurve.is_circle? returns true=Circle: false=Arc or Polygon
                                      ArcCurve.is_polygon? returns true=Polygon: false=Arc or Circle*** THIS Method is built-in from SUp v7.1M1

                                      v1.2 has test to see if v7.1M1 built-in method if not makes is_polygon?
                                      Other methods also trapped so as not to overwrite built-in methods...***

                                      Usage: if not edge.curve.is_loop? then... ### it's an Arc...

                                      They work, but are a clunky temporary fix...***


                                      ArcCurveTests.rb

                                      TIG

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

                                        Updated all of the tests so only load is not built in methods... http://forums.sketchucation.com/viewtopic.php?p=188743#p188743

                                        TIG

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

                                        Advertisement