Su How to determine if a face contains another face?

I would like to know if ruby has a similar api interface to call directly when I want to determine if a face contains another face.

There are several topics here with the similar discussion with a similar conclusion : Not directly.

Some Ideas:


You can use bounding box of faces (The method is inherited from Drawingelement).
The Drawingelement #bounds method is used to retrieve the Geom::BoundingBox bounding a Sketchup::Drawingelement.

Then use BoundingBox #contains? method to determine if a bounding box contains a specific Point3d or the other face BoundingBox object.


You can use The Face #classify_point method to determine
if a given Point3d, aka the other Face #vertices - Vertex#position
is on the referenced Face.


For faces on a base plane, you can think about :The Geom .point_in_polygon_2D method which is used to determine whether a point is inside a polygon.


Edit:
In fact, the face object cannot contain another face object, because the other face object is another object. :wink:
It is possible that the vertices of inner loop of one face is the same position as the vertices of outer loop of the other face…

1 Like

Can you post a screenshot or model of the scenario you have?

Do you have a face that contains another face in the same entities collection? Or are you trying to check two faces that are in different entities collections. The solution will depend on what scenario you have.

1 Like


For example, if plane A contains plane B, how can we determine whether it is contained or not?

You mean “face” instead of “plane”, right? (Plane and face are different concepts in the API)

If you have face A, then you can check its inner loops define another face:

def contains_faces?(face)
  face.loops.any? { |loop|
    next false if loop.outer? # Ignore the outer loop.
    # Take a random edge from the loop and check if it
    # connects to another face on the same plane.
    edge = loop.edges.first
    edge.faces.find { |f| f != face && f.normal.parallel?(face.normal) }
  }
end

p contains_faces?(Sketchup.active_model.selection.first)
1 Like