Angle between two edges in a face?

I'm trying to find the angles between edges in a face. I tried this:
<span class="syntaxdefault"><br />def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">full_angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector1</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> vector2</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> normal </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> angle </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> vector1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector2 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> direction </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> normal </span><span class="syntaxkeyword">%</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> vector1 </span><span class="syntaxkeyword">*</span><span class="syntaxdefault"> vector2 </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> angle </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 360</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">degrees </span><span class="syntaxkeyword"></span><span class="syntaxdefault"> angle if direction </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> 0.0<br /> angle<br />end<br /></span>
normal
is the face normal
vector1
andvector2
both origin from the same vertex and to the opposite verticesBut in a rectangle this yielded one 90 corner and three 270 degree corners.
So how can one find the angle between two edges ( 0...360 degrees ) relative to 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{vb[v]+=1} b.each{k,vvert=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.degreesangle 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