Way to simplify the edges of a square?
-
Hi,
I'm trying to retrieve the 4 vertices of a quadrangle that has divided edges.
But right now I did not found the way to detect when an edge is the continuation of an other and to bypass the result of the middle vertice.
Any help would be great. -
We must assume that the quadrilateral has just 4 corners that are ~90 degrees and the other Vertices are on 'straight' edges.
You need to test each Vertex.
Every Vertex will have a pair of Edges.
These two Edges will each have another 'End' Point [that isn't the tested Vertex].
For each 'End' Point you now find the Vector from the Vertex to the that 'End' Point.
If one Edge's Vector isn't the same as [or equal to the 'reverse' of] the other one then the Vertex isn't on a 'side' and it is at a 'corner'...
. -
How do you check for these things? Are the assisting functions or is it just pure math?
-
Hi,
Do a loop through edges.
If an edge shares a vertex with another edge and if these two edges are colinear, the vertex you are testing is not a corner.Here is the code of such a function that will return an array of corners as Point3d, (no matter how many corners the face has), assuming that parameter "f" is a face entity:
def corners(f) edges=f.edges corners=[] 0.upto(edges.length-1) do |i| e=edges.shift edges.each do |edge| if edge.start==e.start or edge.end==e.start or edge.start==e.end or edge.end==e.end and not e.line[1].parallel?(edge.line[1]) corners.push(e.position) end end end return corners end
Erase face "f" and redraw a new face with the Point3d array
Voilà,
-
It could help to retrieve the vertices of edge from faces that are connected. If an edge of one face do not overlap exactly an adge of another face it just divide these element and it becomes difficult to retrieve the vertices.(I mean before Didier and Tig's reply).
Thanks Didier and Tig.Hope to be back soon with the plugin that takes advantage of this post.
-
Didier,
I made a change because I get an error message in the ruby console about the edge.position in your codeedges.each do |edge| if edge.start==e.start or edge.end==e.start or edge.start==e.end or edge.end==e.end and not (e.line[1].parallel? (edge.line[1])) if edge.start==e.start or edge.start==e.end corners.push(edge.start.position) else corners.push(edge.end.position) end end end
Would you have done it differently?
-
No...
-
You need to look in the API methods for various bits... it's all there...
Make a list of the loop's vertices.
You get a vertex.
You get its point in 3D
You get the vertex's edges.
For the two edges get its other end's vertex and thence its point.
You get the vector between the vertex-point and that end-point in turn.
You see if vertor1==vertor2 [or its 'reverse'].
If they're not 'equal' then it's a corner...
.
Advertisement