Angle between two edges in a face?
-
Are you able to provide a little image which shows the variables vector1, vector2, normal?
Cotty -
@cotty said:
Are you able to provide a little image which shows the variables vector1, vector2, normal?
CottyI added more to the description in the original post.
-
If it is of any importance, "vector1" and "vector2" was just picked at random in the illustration. The red "vector1" might be "vector2" for all I know.
-
The order of how I received the vectors seemed to make the difference.
-
### this code lists each vertex with its angle, for a selected face def vangles() model=Sketchup.active_model ss=model.selection face=ss[0] edges=face.edges edges << edges[0] pairs=[] edges[0..-2].each_with_index{|e,i| pairs << [e,edges[i+1]] } norm=face.normal angles=[];ctr=0 pairs.each{|pr| e0=pr[0] e1=pr[1] vert=e0.start verts=e0.vertices+e1.vertices b=Hash.new(0) verts.each{|v|b[v]+=1} b.each{|k,v|vert=k if v > 1} everts=verts-[vert] vec0=vert.position.vector_to(everts[0]) vec1=vert.position.vector_to(everts[1]) angle=(vec0.angle_between(vec1)) angle=360.degrees-angle if norm==(vec0*vec1).normalize! angles << [ctr, angle.radians] ctr+=1 } puts angles end ###
-
Is it possible to calculate two angles, one for +direction and one for -direction and chose the little one? I don't know about ruby, sorry...
Cotty -
I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625
-
@thomthom said:
I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625
Which presumably has a similar affect as my code ?
-
@tig said:
@thomthom said:
I've solved the problem. Code is posted in this thread: http://forums.sketchucation.com/viewtopic.php?f=180&t=39625
Which presumably has a similar affect as my code ?
Angles seem to be correct, until you add a hole on the face. Then your pairs won't be correct as one pair might contain edges from two different loops.
And my starting position is with a vertex given - and from there I need to work out it's normal. To process the whole face would lead to duplicate processing.
-
My code was a quick example to show that you could get the correct angles.
Of courseedges=face.edges
can easily be replaced withedges=face.outer_loop.edges
or we iterate through the loops to get their edges in turn...
BUT if its for only one vertex it's then easy enough to find the two edges belonging to that vertex [and that face] and run similar code on them to get the angle between them, using the face normal and vectors cross comparison to trap for concave corner angles >180 degrees... remembering to trap for ==180.degrees, as well as < and >...
Advertisement