Move a face perpendicular to it's normal
-
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...
-
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... -
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
-
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 cutsglue_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.
-
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...
Advertisement