# Sorting edges/vertices

**URL:** <https://forums.sketchup.com/t/sorting-edges-vertices/18943>\
**Category:** Ruby API\
**Created:** [January 5, 2016, 10:52am UTC](https://forums.sketchup.com/t/sorting-edges-vertices/18943 "2016-01-05T10:52:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [January 5, 2016, 2:11pm UTC](https://forums.sketchup.com/t/sorting-edges-vertices/18943/4 "2016-01-05T14:11:47Z")

</div>

A face outer\_loop,vertices is returned ccw, any inner loops are cw.  
Taking into account the face.normal.  
Confusion can arise id a face has been reversed and the loop is unchanged.  
Also a face made at z=0 always [initially] faces downwards, irrespective of the loop’s vertices direction.  
So making a face at z=0 with a ccw set of points still has its normal as ==Z\_AXIS.reverse anyway.

To remove the shared edges [I’d forget about loops, normals etc]…

`faces = [face1, face2, face3] edges = [face1.edges, face2.edges, face3.edges].flatten togos = [] edges.each{|e| next unless e.faces[1] ### only look at shared edges shared = true e.faces.each{|f| shared = false unless faces.include?(f) ### skip shared edges which are NOT shared by any of the three faces } togos << e if shared } togos[0].parent.entities.erase_entities(togos) if togos[0]`

Or something similar…  
I fixed it at three faces but of course you can make a more generic format…

---

_[View the full topic](https://forums.sketchup.com/t/sorting-edges-vertices/18943)._
