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

    Triangulate triangles ?

    Scheduled Pinned Locked Moved Plugins
    41 Posts 8 Posters 7.9k Views 8 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.
    • pilouP Offline
      pilou
      last edited by

      Alas I have deserted the Ruby language for a while! 😞

      If you can make a little plugin that will be wonderful 😎

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

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Here is an example code for achieving what you want Pilou...

        
        model = Sketchup.active_model
        ents = model.active_entities
        sel = model.selection
        faces = ents.grep(Sketchup;;Face)
        
        faces.each do |face|
          vertices = face.vertices
          bbox = face.bounds
          cpoint = bbox.center
        
          vertices.each do |vertex|
            p1 = cpoint
            p2 = vertex
            line = ents.add_line p1,p2 
           end
        end
        
        

        Note: Some very pretty geometry start appearing when you keep splitting! πŸ‘

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • renderizaR Offline
          renderiza
          last edited by

          I will do that! πŸ‘

          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

            Beat me to it πŸ˜‰
            You might want to change the
            faces = ents.grep(Sketchup::Face)
            to
            faces = **sel**.grep(Sketchup::Face)
            So then the user changes only selected faces ?
            OR perhaps
            faces = sel.grep(Sketchup::Face) faces = ents.grep(Sketchup::Face) **unless faces[0]**
            so it works on a selection OR everything if there is no selection...

            Also you want to make it undoable, so add
            **model.start_operation('subtri')** faces.each... ...end **model.commit_operation**
            πŸ€“

            TIG

            1 Reply Last reply Reply Quote 0
            • renderizaR Offline
              renderiza
              last edited by

              Hahaha!

              TIG I would be very happy if you modify your existing plugin to add Pilou is feature request. πŸ‘

              I am interested in making this for learning and I have some additional ideas I want to explore. I consider you my mentor TIG and there will never be competition between you and me I promise! πŸ’š

              By the way thanks for the suggestion! πŸ‘

              Here is updated code...

              model = Sketchup.active_model
              ents = model.active_entities
              sel = model.selection
              faces = sel.grep(Sketchup;;Face)
              
              model.start_operation('csplit')
                faces.each do |face|
                  vertices = face.vertices
                  bbox = face.bounds
                  cpoint = bbox.center
              
                  vertices.each do |vertex|
                    p1 = cpoint
                    p2 = vertex
                    line = ents.add_line p1,p2
                  end
                end
                sel.clear
              model.commit_operation
              

              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                OK
                I'll make a simple script and publish it shortly...

                TIG

                1 Reply Last reply Reply Quote 0
                • renderizaR Offline
                  renderiza
                  last edited by

                  Thank you TIG! πŸ‘

                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                    Thanks Pilou !
                    You convinced TIG...
                    And Thanks TIG, I think it's a must have !

                    http://www.polyloop.net/attachment.php?attachmentid=32959&d=1382032801

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

                      Try this http://sketchucation.com/forums/viewtopic.php?p=495430#p495430
                      TriangulateAllFaces...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • cottyC Offline
                        cotty
                        last edited by

                        I think the triangulation is not the same...


                        tri.jpg

                        my SketchUp gallery

                        1 Reply Last reply Reply Quote 0
                        • renderizaR Offline
                          renderiza
                          last edited by

                          Both of these are very useful so maybe add an option to choose between the two.

                          http://s23.postimg.org/sp0h6r557/e_1.png

                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                            To do the former you need to first triangulate all faces, then find each triangle's center using the angles' bisectors' intersections...
                            πŸ˜•

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • renderizaR Offline
                              renderiza
                              last edited by

                              Not as easy as using the center of face.bounds.center is it. πŸ˜•

                              If I find the best way to do it with code I'll let you know...Best of luck! πŸ‘

                              [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                              1 Reply Last reply Reply Quote 0
                              • renderizaR Offline
                                renderiza
                                last edited by

                                I sure don't call the code below a success but its definitely interesting...

                                http://s13.postimg.org/yerdljl8n/eee.jpg

                                
                                model = Sketchup.active_model
                                ents = model.active_entities
                                sel = model.selection
                                faces = sel.grep(Sketchup;;Face)
                                
                                model.start_operation('csplit')
                                  faces.each do |face|
                                    vertices = face.vertices
                                    edges = face.edges
                                    bbox = face.bounds
                                    cpoint = bbox.center
                                
                                   edges.each do |e|
                                      e1 = e.start.position
                                      e2 = e.end.position      
                                
                                      x = (e2.x + e1.x) / 2
                                      y = (e2.y + e1.y) / 2 
                                      z = (e2.z + e1.z) / 2
                                
                                      vertices.each do |vertex|
                                        p1 = [x, y, z]
                                        p2 = vertex
                                        line = ents.add_line p1,p2
                                      end
                                    end    
                                  end
                                  sel.clear
                                model.commit_operation
                                

                                Note: I also find strange that new edges don't intersect with each othere making a new vertex...why is this?

                                [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                1 Reply Last reply Reply Quote 0
                                • renderizaR Offline
                                  renderiza
                                  last edited by

                                  If the second time you apply script you do each face individually inside a group, then you get very pretty geometry. πŸ˜›

                                  http://s15.postimg.org/3zyfm7ayz/pp1.jpg

                                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                  1 Reply Last reply Reply Quote 0
                                  • JQLJ Offline
                                    JQL
                                    last edited by

                                    Renderiza,

                                    That's not success, that's brilliance!

                                    I'll start designing tiles right away...

                                    Thanks!

                                    JQL

                                    www.casca.pt
                                    Visit us on facebook!

                                    1 Reply Last reply Reply Quote 0
                                    • renderizaR Offline
                                      renderiza
                                      last edited by

                                      Wish you success or better yet brilliance in your designs! πŸ’š

                                      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                                        you make big progress and be near the success! β˜€

                                        @unknownuser said:

                                        Not as easy as using the center of face.bounds.center is it. πŸ˜•

                                        If I find the best way to do it with code I'll let you know.

                                        Why not take the image of the first post as "pseudo code" ?

                                        • Calculate the point x,y,z crossing of 2 lines from 2 vertices to their middle opposite edge
                                          (point can be also the calculate center of gravity of 3 points! πŸ˜‰
                                        • draw 3 lines from this point to the 3 vertices

                                        Tig has finalized his "triangulate" method!
                                        Medians stay in race! πŸ˜„

                                        Triangulate all faces by Tig (function was repeated for a sort of fractal system - only 3 triangles at start)
                                        nomedian.jpg

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

                                        1 Reply Last reply Reply Quote 0
                                        • renderizaR Offline
                                          renderiza
                                          last edited by

                                          Thanks guys! Will definitely study your suggestions. πŸ‘

                                          [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

                                          1 Reply Last reply Reply Quote 0
                                          • jolranJ Offline
                                            jolran
                                            last edited by

                                            I Think you could use the circumcentre as well, for skewed triangles.. Maybe that's what Pilou is trying to Point out.

                                            Here's some code I'm using for that. You might have to rewrite it to fit your needs..
                                            I just ripped it out from a plugin I'm working on..

                                            # Arguments need 3 point3D objects from triangle.
                                            def points3_circumC(p1,p2,p3) #(Only 2 lines is actually needed for calculation)
                                            	
                                            	#Init Vectors for calculation.
                                            	vec1  = p1.vector_to(p2) 
                                            	vec2  = p1.vector_to(p3) 
                                            	fakeZ = vec1.cross(vec2) #cross Plane...
                                            	#midpoints
                                            	mp1 = p1.offset(vec1, vec1.length/2)
                                            	mp2 = p1.offset(vec2, vec2.length/2)
                                            	#cross vectors..
                                            	vec1 = vec1.cross(fakeZ)
                                            	vec2 = vec2.cross(fakeZ)
                                            	#lines
                                            	line1 = [mp1, vec1]
                                            	line2 = [mp2, vec2]
                                            	return c = Geom.intersect_line_line(line1, line2) #point3D
                                            end
                                            

                                            edit: Ehh.. looks like TIG already bashed out a working plugin for this.

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

                                            Advertisement