Finding Vertices of a Group (Solid)

I’m a little stuck right now on this problem and I’m not seeing an easy or efficient solution to the problem.

I basically create a face and a path and use the followme method to extrude along the path. The original face remains and so I am able to grab that face from its original handle and manipulate its vertices as required.

The hard problem is how to acquire the vertices of the face at the other end of the solid (at the end of the extrusion). My proposed algorithm is to check all of the faces of the group and compare the area of each with the original face, if they match then it should be the opposite face however this method is not totally 100% bullet proof.

Two ideas:

  1. If you know (you should) the last segment of the path you can make an additional comparison if the face normal parallel to the last part of the path:
    # parallel? (vector2) ⇒ Boolean

  2. If the last point of the path should be inside the questionable face you can check with:
    # classify_point (point) ⇒ Integer

1 Like

The first check you suggested can be checked. An even more exact match can be obtained by using the samedirection method for vectors.

This does get me a bit closer, but again its still not 100%, there are cases where it will fail. The second test suggested won’t work as given but it does have me thinking.

Another possible check might involve the bounds of the face as a check.

…or you can check if the “End” point is on the plane of the “good_face”
# plane ⇒ Array(Float, Float, Float, Float)
# on_plane? (plane) ⇒ Boolean

1 Like

Here is what I have so far:

group2faces = entities2.grep(Sketchup::Face)
endfacelist = group2faces.find_all {|face| face.normal.samedirection?(dirvec) && face.area.round(3) == face_area && face.to_s != new_face2.to_s }
endface = endfacelist[-1]

The red face is the end face that the algorithm is finding (colored the face red when found):

Three other faces in the footing group meet the criteria however by choosing the last one in the narrowed down list of four it grabs the end face. I’m not sure how reliable this is but after a number of tests it does seem pretty reliable.

Is it always the case that their normal will be in the same direction?
You could do a compare on their area + the total length of the outer loop.

The only way to be 100% sure is in my opinion to not rely on SketchUp’s tools to create the extrusion but to calculate and create the geometry yourself.

You know the ‘line’ of the final path edge | or you know the final two vertices relating to the final path edge.
Either gives you a vector.
Iterate the group.entities and find all faces with a normal matching that vector.
From that limited set of faces use the point of the final vertex in the path and test for that point being on a face.plane >>> to hit
To further check… the area and the dimensions of the start face and final face should be the same ? [assuming the path starts perpendicularly to the start-face]


…and if your path is always known to fall on the edges of the extrusion use


to check that it is on the face or its edge or vertex [you can also use it to check its on-plane-ness too]…
Class: Sketchup::Face — SketchUp Ruby API Documentation
There are several ‘hits’ available…

1 Like

Does anyone see anything wrong with the code sample above? It seems to work 99.9% of the time. I’m not saying it won’t fail but so far it looks pretty solid.

which would it choose?

I agree with Tig that you already know the path end, so use it…