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

    Flattening 3d triangle

    Scheduled Pinned Locked Moved Development Discussions
    3 Posts 2 Posters 735 Views 1 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.
    • gilboonetG Offline
      gilboonet
      last edited by

      Hello, flattening 3d triangle is very useful for all kinds of projects, and it's not available at this moment on V2, so here's a little function that does it. It comes from this discussion : https://stackoverflow.com/a/8051489

      function d2ize(p){
      var x0 = p[0][0], y0 = p[0][1], z0 = p[0][2],
          x1 = p[1][0], y1 = p[1][1], z1 = p[1][2],
          x2 = p[2][0], y2 = p[2][1], z2 = p[2][2]
          
      var X0 = 0, Y0 = 0
      var X1 = Math.sqrt((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) + (z1 - z0)*(z1 - z0)),
          Y1 = 0
      var X2 = ((x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0) + (z1 - z0) * (z2 - z0)) / X1,
          Y2 = Math.sqrt((x2 - x0)*(x2 - x0) + (y2 - y0)*(y2 - y0) + (z2 - z0)*(z2 - z0) - X2*X2)
          
      return [[X0, Y0], [X1, Y1], [X2, Y2]]
      
      }
      
      1 Reply Last reply Reply Quote 0
      • z3devZ Offline
        z3dev
        last edited by

        Cool. But be careful as the boolean operations can create polygons with more than three (3) vertices. Also, some of the primitives create polygons with four (4) vertices.

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

          Thank you. I only work with triangulated models for coding simplicity, even if later (for designs clarity) I usually remove walls between co-planar neighbours. I will certainly soon start to make V2 versions of my code, was only missing this, but for the moment I'm making a vanilla JS pattern editor.

          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