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.
    • R Offline
      remus
      last edited by

      Sorry, i forgot to add that it should also be a curve/arccurve. Beyond that the distinction is pretty arbitrary anyway because of the segmented nature of circles in SU.

      http://remusrendering.wordpress.com/

      1 Reply Last reply Reply Quote 0
      • pilouP Offline
        pilou
        last edited by

        Ingenuous suggestion πŸ’š
        You can't read the "Entity info" by ruby? πŸ˜‰

        Frenchy Pilou
        Is beautiful that please without concept!
        My Little site :)

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

          @tig said:

          If the ArcCurve Curve's Vertices are not looped

          I check the radius of the ArcCurve to work out if it's a Circle/Polygon. Less entity iteration that way.

          
          def self.is_circle?(ent)
          	# (i) A bug in SU makes extruded circles into Arcs with .end_angle of 720 degrees when reopening the file.
          	# Instead of checking for 360 degrees exactly, we check for anything larger as well. A 2D arc
          	# can't have more than 360 degrees.
          	
          	return false unless ent.kind_of?(Sketchup;;Edge) && ent.curve && ent.curve.kind_of?(Sketchup;;ArcCurve)
          	arc_curve = ent.curve
          
          	# This doesn't work. Maybe due to rounding errors?
          	#return (arc_curve.end_angle - arc_curve.start_angle >= 360.degrees) ? true ; false
          
          	return ((arc_curve.end_angle - arc_curve.start_angle).radians >= 360) ? true ; false
          end
          
          

          @tig said:

          So how does SUp know the difference between a Circle/Arc and a Polygon

          SU must have more info internally which isn't hooked up to the Ruby. 😞

          @remus said:

          Sorry, i forgot to add that it should also be a curve/arccurve. Beyond that the distinction is pretty arbitrary anyway because of the segmented nature of circles in SU.

          Polygons comes out as an ArcCurve - so still no go.

          @unknownuser said:

          Ingenuous suggestion πŸ’š
          You can't read the "Entity info" by ruby? πŸ˜‰

          Nope. 😞

          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

            That was the only method I could think of as well. But for what I want to use it for (my Selection Toys plugins - that can potentially evaluate millions of entities in some models) it would be too slow. 😞

            I guess an evaluation that doesn't require to test-push-pull the polygon/circle is something to ask for in a feature request?

            I tried to have a quick look at the private methods - hoping to find something locked up there. Might try to have another look.

            Crosswords puzzles are boring. SU Ruby challenges are much more fun! πŸ˜„

            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

              I had hopes for .typename to work - but alas. 😞

              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

                You would parse down the entities quite quickly ?

                all_entities ==1000000
                all_edges ==500000
                edge.curve ==50000
                is ArCurve ==25000
                ArcCurve.is_loop? ==10000
                that ArcCurve.is_polygon? ==1000

                ???

                BUT, it would be MUCH easier if we had access to the internal methods that SUP has to return Polygon etc in the Entity Info Panel !!!

                TIG

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

                  Lateral solution [at last !!!]... πŸ€“
                  which we can now write into three new methods - ArcCurve.is_loop? [returns true if it's a Circle OR a Polygon; false if it's an Arc] and also ArcCurve.is_polygon? [true if it's a Polygon and false if it's a Circle or an Arc], or ArcCurve.is_circle? [true if it's a Circle and false if it's a Polygon or an Arc[/ruby] ...

                  EDIT: added all 'three' methods...

                  
                  class Sketchup;;ArcCurve
                    def is_loop?()### circle OR polygon
                      self.edges.each{|e|
                        e.vertices.each{|v|
                          if not v.edges[1]
                            return false ### it's an arc
                            break
                          end#if
                        }
                      }
                      return true
                    end#if
                    def is_polygon?()
                      self.edges.each{|e|
                        e.vertices.each{|v|
                          if not v.edges[1]
                            return false ### it's an arc
                            break
                          end#if
                        }
                      }
                      ### if we get here it might be a polygon !!!
                      model=Sketchup.active_model
                      entities=model.active_entities
                      edge=self.edges[0]
                      all_connected=edge.all_connected
                      tgroup=entities.add_group(all_connected)
                      es=edge.start.position
                      ee=edge.end.position
                      group=tgroup.copy
                      tgroup.explode
                      gents=group.entities
                      gedges=[]
                      gents.each{|e|gedges<<e if e.class==Sketchup;;Edge}
                      gedge=nil
                      gedges.each{|e|
                        e.smooth=false
                        e.soft=false
                        gedge=e if (e.start.position==es and e.end.position==ee)or(e.start.position==ee and e.end.position==es)}
                      ### remove all faces so only face and pushpull's remain
                      gents.each{|e|e.erase! if e.class==Sketchup;;Face}
                      gedge.find_faces
                      face=nil
                      gents.each{|e|face=e if e.class==Sketchup;;Face}
                      return false if not face
                      face.pushpull(1.0)
                      edges=[]
                      gents.each{|e|edges<<e if e.class==Sketchup;;Edge}
                      edges.each{|e|
                        if e.smooth? and e.soft?
                          group.erase! if group.valid?
                          return false ### a circle
                        end#if
                      }
                      group.erase! if group.valid?
                      return true ### a polygon
                    end#def
                    def is_circle?()
                      self.edges.each{|e|
                        e.vertices.each{|v|
                          if not v.edges[1]
                            return false ### it's an arc
                            break
                          end#if
                        }
                      }
                      ### if we get here it might be a polygon !!!
                      model=Sketchup.active_model
                      entities=model.active_entities
                      edge=self.edges[0]
                      all_connected=edge.all_connected
                      tgroup=entities.add_group(all_connected)
                      es=edge.start.position
                      ee=edge.end.position
                      group=tgroup.copy
                      tgroup.explode
                      gents=group.entities
                      gedges=[]
                      gents.each{|e|gedges<<e if e.class==Sketchup;;Edge}
                      gedge=nil
                      gedges.each{|e|
                        e.smooth=false
                        e.soft=false
                        gedge=e if (e.start.position==es and e.end.position==ee)or(e.start.position==ee and e.end.position==es)}
                      ### remove all faces so only face and pushpull's remain
                      gents.each{|e|e.erase! if e.class==Sketchup;;Face}
                      gedge.find_faces
                      face=nil
                      gents.each{|e|face=e if e.class==Sketchup;;Face}
                      return false if not face
                      face.pushpull(1.0)
                      edges=[]
                      gents.each{|e|edges<<e if e.class==Sketchup;;Edge}
                      edges.each{|e|
                        if e.smooth? and e.soft?
                          group.erase! if group.valid?
                          return true ### a circle
                        end#if
                      }
                      group.erase! if group.valid?
                      return false ### a polygon
                    end#def
                  end#class
                  
                  

                  πŸ’­

                  TIG

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

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

                    Guess not.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • 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
                                            • 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