JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    2D slice from extruded polygon after substraction

    Scheduled Pinned Locked Moved Development Discussions
    9 Posts 4 Posters 2.2k Views 2 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.
    • IonI Offline
      Ion
      last edited by

      Hello

      First of all, would like to thank the developers who made this framework possible.

      I am starting off with a linearly extruded polygon and then subtract a cube out of it.
      Screenshot 2021-01-19 at 23.50.53.png
      Screenshot 2021-01-20 at 00.13.03.png

      Then I want to get a 2d slice in vertical plane. To achieve this I am going through all polygons and all vertices from a very thin slice ignoring all polygons with same z-axis (walls) and extract the x,y and ignore the z altogether.

      this.profile3D.polygons.forEach(function (polygon, index) {
            let local_this2 = local_this
      
            polygon.vertices.forEach(function (v, i) {
              let av_arr = polygon.vertices.map(function (x) {
                return parseInt(x[1] as any)
              }) as Array<number>
      
              let is_vertical = new Set(av_arr).size < 2
              if (!is_vertical) {
                local_this2.profile2D.push([v[0], v[2]])
              }
            })
          })
        }
      

      Finally I sort of get the 2d slice but with some points "tangled" (shape front end)
      Screenshot 2021-01-20 at 00.02.42.png
      Screenshot 2021-01-20 at 00.02.05.png

      How can I make sense of the mesh's structure to be able to walk the mesh so points are in order and correctly joined?
      I've excluded the "walls". The mesh seems to be a 4 pct polygon and sometimes a 3 point polygon. More complex shapes turn out more tangled points.
      Is there a common layout of the mesh that I can lookup somewhere else? I have tried checkout out the code but could not figure it out.

      I have also tried extracting the x,y of any 2 corners of the 4 pct polygon which are not "vertical walls/sides"

      this.profile3D.polygons.forEach(function (polygon, index) {
            let local_this2 = local_this
      
            polygon.vertices.forEach(function (v, i) {
              let av_arr = polygon.vertices.map(function (x) {
                return parseInt(x[1] as any)
              }) as Array<number>
      
              let is_vertical = new Set(av_arr).size < 2
              if (!is_vertical) {
                local_this2.profile2D.push([polygon.vertices[2][0], polygon.vertices[0][2]])
              }
            })
          })
        }
      

      Artefacts like this started to come out but no luck with any combination.
      Screenshot 2021-01-20 at 00.20.09.png

      Any suggestions are appreciated. Thanks!
      P.S Wish my skills would be good enough to contribute.

      z3devZ 1 Reply Last reply Reply Quote 0
      • z3devZ Offline
        z3dev @Ion
        last edited by z3dev

        @Ion Welcome!

        You are already doing things that 'normal' designers don't attempt. 🙂

        There's a piece of code that does a very simular thing, converting 3D polgons (from boolean operations) to 2D sides. This might help you to understand a little more about the 2D geometry (geom2).

        https://github.com/jscad/OpenJSCAD.org/blob/V2/packages/modeling/src/operations/booleans/fromFakePolygons.js

        Ion 0I 2 Replies Last reply Reply Quote 0
        • gilboonetG Offline
          gilboonet
          last edited by

          Hello, did you try to unify the polygons ? I have some code that does the same kind of thin slicing and the 2d slice is an union of the polygons.

          Ion 0I 1 Reply Last reply Reply Quote 0
          • Ion 0I Offline
            Ion 0 @gilboonet
            last edited by

            @gilboonet The whole 2d contour is one single polygon of points. where should i get multiple polygons from? from the sides?

            gilboonetG 1 Reply Last reply Reply Quote 0
            • Ion 0I Offline
              Ion 0 @z3dev
              last edited by

              @z3dev thanks!

              1 Reply Last reply Reply Quote 0
              • gilboonetG Offline
                gilboonet @Ion 0
                last edited by

                @Ion-0 If I approximate your design, and get a slice of it, I have a set of 3 polygons
                Capture d’écran de 2021-01-20 22-50-46.png

                Ion 0I 1 Reply Last reply Reply Quote 0
                • Ion 0I Offline
                  Ion 0 @z3dev
                  last edited by Ion 0

                  @z3dev
                  I have got it working using the routine pointed at by you. it was a bit confusing as it throws error for polygons with more than "2 dimension" and the axis was different.

                  2021-01-30 21.58.18.jpg

                  gilboonetG 1 Reply Last reply Reply Quote 0
                  • Ion 0I Offline
                    Ion 0 @gilboonet
                    last edited by

                    @gilboonet Thanks for the response. I believe you mean the "sides" are rendered using polygons. indeed they are lots of polygons. I might give that a try using the 2d constructive geometry. i've gotten the result right using the fromfakepolygons routine.

                    1 Reply Last reply Reply Quote 0
                    • gilboonetG Offline
                      gilboonet @Ion 0
                      last edited by

                      @Ion-0 That's great !

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • First post
                        Last post
                      Powered by NodeBB | Contributors