Flatten a Face to 2D

I’m trying to figure out an “easy” way to take a face and flatten that face to the 2D XY plane.

Has anyone ever tried doing something like this?

My first crack at it would be to collect all the vertices and then cycle through the points setting the z-values to zero.

The problem is that the face will end up faceted after the operation.

Yes TIG has had such a plugin on SketchUcation for many years. At least since the SU7 days.

Will not work as Vertex objects do not have a z= method.

What you rather would need to do is transform each vertex using the Entities#transform_by_vectors method. This requires that for each vertex, you create a -Z vector whose length is equal to the vertex’s z value.

def flatten_face(face)
  ents = face.parent.entities
  verts = face.vertices
  vectors = verts.map { |v| Geom::Vector3d.new(0, 0, -v.position.z) }
  ents.transform_by_vectors(verts, vectors)
end
3 Likes

You could try to collect all edges before flattening, then iterate over the new edges and see if they are joining two coplanar faces.

Not necessary because the Entities#transform_by_vectors method applies the changes in a single operation. (See the docs.)

Nat was only speculating that the approach he was contemplating would result in faceted faces. (However as I pointed out, his contemplated approach would not work as changing the z values of points would not actually affect the vertices he got them from.)

1 Like