# Find the lower left corner of the quad

I want to lay out the components from the bottom left corner of a face.
I wrote a code to get the nearest point of the quadrilateral from the origin and sort the four endpoints.
But many of the actual points closest to the origin are not the lower left corner of the quadrilateral，just like the picture.
How can I do to find the points in the lower left corner of the quadrilateral and sort them?
I would be grateful if you could help me with the answer.

have a look at the :corner method…

`entity.bounds.corner(0)` may be what you need, unless there is rotation or skew…

john

If you want to order corners (vertices) by say their height you can do something like this:

``````vertices.sort_by { |v| v.position.z }
``````

If you want to sort them by their “bottom-leftness” you can temporarily transform the coordinates before sorting:

``````transformation = Geom::Transformation.new(Geom::Vector3d.new(1, 0, 1))
vertices.sort_by { |v| v.position.transform(transformation).z }``````
1 Like

vertices.sort_by { |v| v.position.z }

Fails because it is passing three element arrays [aka point3ds], and that will not work with .position - because that only applies to a vertex

So using…

``````vertices = [[3,2,1], [2,3,4], [4,2,1], [5,6,2]]
vertices.sort_by { |v| v.z }
``````

WILL work properly…

It doesn’t fail if vertices are vertices, only if you for whatever reason put something that isn’t vertices in the variable named vertices.

@skyfire, I think your post is related to your preivous posts and so I think you’re looking for something like this :

``````#Collect the selected face positions
face_entity = Sketchup.active_model.selection[0]
face_positions = face_entity.vertices.collect{|v| v.position}

#Order the face positions according to their distance to the lower left corner face's space and select the closest one
ref_position = face_entity.bounds.min
closest_position_from_bottom_left = face_positions.sort_by{|p| p.distance(ref_position)}[0]

#Find were the closest position from the bottom left corner is in the list and rebuild an ordered list
closest_position_index = face_positions.index(closest_position_from_bottom_left)
ordered_face_positions = face_positions[closest_position_index ..-1] \
+ face_positions[0...closest_position_index]``````

thanks so much sir,I succeed using your ways!