sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Move a face perpendicular to it's normal

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 883 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.
    • thomthomT Offline
      thomthom
      last edited by

      I would like to move a face by a certain distance perpendicular to it's normal. But I can't work out how.

      I know the face's normal, and I know the offset. But I can't work out how to create a transformation that will do this...

      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

        Found a way. Too tired to post the method now though.
        Feel free to post suggestions anyway. It'd be interesting to see if I'm thinking straight...

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          I worked out this method, but its not perfect (at all). I tried to do it all in a single transformation, but I don't think this will work. Try it on a sphere and on a landscape grid made from the sandbox tools. You'll see plenty of irregularities. Send in a selection set and the offset distance to the method and it returns an array of the newly offset faces.

          But then again, it might be that I have written something incorrectly here. Thats always a HUGE possibility. So look it over and maybe I've just coded it poorly.

          model = Sketchup.active_model
          selection = model.selection
          
          def transform_faces_by_normals( sel, distance )
          model = Sketchup.active_model
          entities = model.active_entities
          faces = []
          vectors = []
          norm1 = []
          sel.each do |e|
          	if e.typename == "Face"
          		norm = e.normal
          		norm[0] *= distance
          		norm[1] *= distance
          		norm[2] *= distance
          		vectors << norm
          		faces << e
          	end
          end
          return_new_faces = entities.transform_by_vectors( faces, vectors )
          end
          
          specified_distance = 100
          new_faces = transform_faces_by_normals( selection, specified_distance )
          new_faces.to_a
          

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

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

            Good morning everyone.

            Here's how I did it.
            But first I have to mention that what I am actually doing is not moving a face, I just used that to simplify the question.

            I've been working on making a plugin which let you make cutout component which cuts two faces. Say you have a 300mm thick wall, and place a cutout component which extrudes 300mm and intersects with the parallel wall face.
            I find which edges intersects with the other face and creates a new cutout component from that. This new component has to be placed 300m parallel to the original cutout component in an perpendicular direction.

            The original cutout component is refered to as cutout and the face it cuts glue_face. dcut is the new cutout component I generated.

            
            # To offset the component we create a scale transformation using
            # the offset distance. We use that transformation to size up the
            # glue_face's vector. When we use that vector to create a new
            # transformation, which we cross with the cutout instance's 
            # transformation, we have a transformation which will place the
            # new cutout component correctly offset perpendicular to the
            # original cutout.
            scale = Geom;;Transformation.scaling( offset )
            vector = glue_face.normal.axes.z.transform( scale )
            offset_transformation = Geom;;Transformation.new( vector )
            instance_transformation = offset_transformation * t
            
            # Insert double cutout component and glue it to the perpendicular face.
            instance = model.active_entities.add_instance(dcut, instance_transformation)
            instance.glued_to = cut_face
            
            

            This seems to work even if the wall is positioned in any kind of position in the modelspace.

            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 think I could also have used Point3d.offset http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#offset, generating an transformation from the offset point, but it doesn't look like the code would be any shorter...

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

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

              Advertisement