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

    Triangulate triangles ?

    已排程 已置頂 已鎖定 已移動 Plugins
    41 貼文 8 Posters 7.9k 瀏覽 8 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • cottyC 離線
      cotty
      最後由 編輯

      I think the triangulation is not the same...


      tri.jpg

      my SketchUp gallery

      1 條回覆 最後回覆 回覆 引用 0
      • renderizaR 離線
        renderiza
        最後由 編輯

        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 條回覆 最後回覆 回覆 引用 0
        • TIGT 離線
          TIG Moderator
          最後由 編輯

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

          TIG

          1 條回覆 最後回覆 回覆 引用 0
          • renderizaR 離線
            renderiza
            最後由 編輯

            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 條回覆 最後回覆 回覆 引用 0
            • renderizaR 離線
              renderiza
              最後由 編輯

              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 條回覆 最後回覆 回覆 引用 0
              • renderizaR 離線
                renderiza
                最後由 編輯

                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 條回覆 最後回覆 回覆 引用 0
                • JQLJ 離線
                  JQL
                  最後由 編輯

                  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 條回覆 最後回覆 回覆 引用 0
                  • renderizaR 離線
                    renderiza
                    最後由 編輯

                    Wish you success or better yet brilliance in your designs! 💚

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

                    1 條回覆 最後回覆 回覆 引用 0
                    • pilouP 離線
                      pilou
                      最後由 編輯

                      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 條回覆 最後回覆 回覆 引用 0
                      • renderizaR 離線
                        renderiza
                        最後由 編輯

                        Thanks guys! Will definitely study your suggestions. 👍

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

                        1 條回覆 最後回覆 回覆 引用 0
                        • jolranJ 離線
                          jolran
                          最後由 編輯

                          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 條回覆 最後回覆 回覆 引用 0
                          • renderizaR 離線
                            renderiza
                            最後由 編輯

                            It works! 😍

                            http://s9.postimg.org/3oou2krkf/yay.jpg

                            Here is the 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|
                                v = face.vertices
                            
                                cx = v[0].position.x + v[1].position.x + v[2].position.x
                                cy = v[0].position.y + v[1].position.y + v[2].position.y   
                                cz = v[0].position.z + v[1].position.z + v[2].position.z 
                            
                                px = cx / 3
                                py = cy / 3 
                                pz = cz / 3 
                            
                                v.each do |vertex|
                                  p1 = [px, py, pz]
                                  p2 = vertex
                                  line = ents.add_line p1,p2
                                end
                              end
                              sel.clear
                            model.commit_operation
                            

                            Note: At the moment the above code works with triangles only.

                            For squares we can use the code bellow...

                            
                            model = Sketchup.active_model
                            ents = model.active_entities
                            sel = model.selection
                            faces = sel.grep(Sketchup;;Face)
                            
                            model.start_operation('csplit')
                              faces.each do |face|
                                v = face.vertices
                            
                                cx = v[0].position.x + v[1].position.x + v[2].position.x + v[3].position.x
                                cy = v[0].position.y + v[1].position.y + v[2].position.y + v[3].position.y  
                                cz = v[0].position.z + v[1].position.z + v[2].position.z + v[3].position.z 
                            
                                px = cx / 4
                                py = cy / 4 
                                pz = cz / 4 
                            
                                v.each do |vertex|
                                  p1 = [px, py, pz]
                                  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 條回覆 最後回覆 回覆 引用 0
                            • renderizaR 離線
                              renderiza
                              最後由 編輯

                              The following code will work on all geometry types like triangle, square, ect...

                              model = Sketchup.active_model
                              ents = model.active_entities
                              sel = model.selection
                              faces = sel.grep(Sketchup;;Face)
                              @addx = []
                              @addy = []
                              @addz = []
                              
                              model.start_operation('csplit')
                                faces.each do |face|
                                  @addx.clear
                                  @addy.clear
                                  @addz.clear
                              
                                  v = face.vertices
                                  num = v.length
                              
                                  v.each_with_index {|vert,i|
                                    @addx << " + v[#{i}].position.x"
                                    @addy << " + v[#{i}].position.y"
                                    @addz << " + v[#{i}].position.z"
                                  }
                              
                                  ax = @addx * ","
                                  sumx = ax.delete ","
                              
                                  ay = @addy * ","
                                  sumy = ay.delete ","
                              
                                  az = @addz * ","
                                  sumz = az.delete ","
                              
                                  cx = eval("#{sumx}")
                                  cy = eval("#{sumy}")
                                  cz = eval("#{sumz}")
                              
                                  px = cx / num
                                  py = cy / num
                                  pz = cz / num
                              
                                  v.each do |vertex|
                                    p1 = [px, py, pz]
                                    p2 = vertex
                                    line = ents.add_line p1,p2
                                  end
                              
                                end
                                sel.clear
                              model.commit_operation
                              
                              

                              Note: To test code above you can copy & paste it to one of this ruby consoles...
                              http://renderizastudio.blogspot.com/2013/06/top-ruby-consoles-for-sketchup.html

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

                              1 條回覆 最後回覆 回覆 引用 0
                              • renderizaR 離線
                                renderiza
                                最後由 編輯

                                With the help of Dan Rathbun the code was improved! Because string manipulation in Ruby can be slow he figured a way to do it without strings.

                                Here is the new code...

                                  def csplit()
                                    #
                                    model = Sketchup.active_model
                                    ents = model.active_entities
                                    sel = model.selection
                                    faces = sel.grep(Sketchup;;Face)
                                    #
                                    model.start_operation('csplit')
                                      #
                                      faces.each do |face|
                                        #
                                        sum = Geom;;Point3d.new(0,0,0)
                                        #
                                        verts = face.vertices
                                        n = verts.size.to_f
                                        # use API Geom;;Point3d.+ instance method;
                                        verts.each {|v| sum += ORIGIN.vector_to(v.position) }
                                        #
                                        avg = Geom;;Point3d.new( sum.x/n, sum.y/n, sum.z/n )
                                        #
                                        verts.each {|v| ents.add_line( avg, v ) }
                                        #
                                      end # each face
                                      #
                                    model.commit_operation
                                    #
                                  rescue => e
                                    #
                                    puts "Error <#{e.class.name}; #{e.message} >"
                                    puts e.backtrace if $VERBOSE
                                    #
                                    model.abort_operation
                                    #
                                  else # when no errors;
                                    #
                                    sel.clear
                                    #
                                  end # csplit()
                                
                                  csplit()
                                
                                

                                If you have the time make sure to thank Dan...Cheers!

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

                                1 條回覆 最後回覆 回覆 引用 0
                                • pilouP 離線
                                  pilou
                                  最後由 編輯

                                  Seems very cool! 👍
                                  Waiting the definitive little plugin more easy than a copy past inside the ruby console! 😉

                                  And you will your name in the index Plugin automatic list by Jim! 😎

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

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • renderizaR 離線
                                    renderiza
                                    最後由 編輯

                                    Ok I will start working on that ASAP!!!

                                    By the way you like the name "FaceSplit"?

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

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • pilouP 離線
                                      pilou
                                      最後由 編輯

                                      "Bermuda's Triangles' Gravity" will be also funny! 😉

                                      https://encrypted-tbn0.gstatic.com/images?q=tbn;ANd9GcQVDrKcLEC7T4VaspbQcQc_3tRmnEFfnCvFR7lAKksR_Dcd6PSkIQ

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

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • renderizaR 離線
                                        renderiza
                                        最後由 編輯

                                        I am glad you liked "FaceSplit"! 🤣

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

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • renderizaR 離線
                                          renderiza
                                          最後由 編輯

                                          Here is the logo...

                                          Big:

                                          http://s8.postimg.org/f4mis2579/Face_Split.png

                                          Small:

                                          http://s14.postimg.org/4n72xxfrh/Face_Split54.png

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

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • renderizaR 離線
                                            renderiza
                                            最後由 編輯

                                            Here is the plugin main page... http://sketchucation.com/forums/viewtopic.php?p=495689#p495689

                                            I used FaceSplit as name but if you guys come up with better name that is short & catchy then it will be easy to change.'

                                            Cheers! 👍

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

                                            1 條回覆 最後回覆 回覆 引用 0
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • 第一個貼文
                                              最後的貼文
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement