Merging two co-linear edges
-
Given a set of connected co-linear edges, you want to merge two of the edges.
I have tried the "repair edges" method of creating a temp edge at the common vertex of the two edges and then erasing that edge. This results in merging more than the two edges connected to that vertex. It affects the edges connected to the edges connecting the vertex.
I don't want to erase and recreate the two edges I want to merge, as it leads to problems when faces are connected. I could go on an recreate the edges as well, but then you're getting a very slow function - plus any Projected UV mapping will lose their Projection property.
So are anyone aware of any way to merge two, and only those two, co-linear edges on a set of multiple co-linear edges?
-
Assuming you have checked that they are colinear, and you have a reference to the 2 edges e0 and e1...
There are 3 vertices...
vs=(e0.vertices+e1.vertices).flatten
find the one that's shared by both edges
shared=(e0.vertices & e1.vertices)[0]
Check that 'shared
' only has edges e0/e1 ...
If so then fFirst another vertex
start=(vs-[shared])[0] vec=shared.position.vector_to(start.position)
Now make an entities transformation (assumingents=e0.parent.entities
)
ents.transform_by_vectors([shared],[vec])
If you could collect all such vertices and their vector adjustments but you might trip up by having deleted a vertex you are later transforming so I showed it in individual steps...
this should combine the two vertices into one ? -
Ah! Yes - that should work. However, one need to "heal" the zero length edge as well. (Creating a zero length edge in a group at the position of the zero length edge you want to remove, then explode the group - that will remove both zero length edges. Ugh, wish there was a nice way for this. )
Doing it in bulk could be tricky - as you mention. Will see how I handle that.
-
I've adjust my example a bit because 'count' is not available in Ruby 1.8!
It actually easier to do as I now show with []&[]... -
As we have [or can easily get] a reference to this now zero length edge, presumably we can't successfully .erase! it ? Good if we could.
The explode of a second zero length edge onto the vertex will auto-update and remove the rogue one anyway... -
Yea, erasing the zero length edge would make a gap between adjacent edges. ...I think... might need to verify that again.
Advertisement