Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding internal angles of polygon

I have some lines that their intersection describes a polygon, like this:

main polygon

I know the order of the lines, and their equations.

To find the internal angles, I found each lines orientations. But I've got confused as subtracting two lines orientation would give two different angles, even if I do it in the order of polygon's sides.

For example, in the following image, if I just subtract the orientation of the lines, I would get any of the following angles:

defect 1

What made me more confused, is when the polygon is not convex, I will have angles greater than 180, and using my approach I don't get the correct angle at all:

defect 2

And I found out that this way of approaching the problem is wrong.

So, What is the best way of finding the internal angles using just the lines? I know for a convex polygon, I may find vectors and then find the angle between them, but even for P6 in my example the vector approach fails.

Anyway, I prefer a method that won't include a conditional case for solving that concavity problem.

Thanks.

like image 781
Kamyar Infinity Avatar asked Aug 23 '12 01:08

Kamyar Infinity


1 Answers

With ordered lines it is possible to find points of intersection (polygon vertexes) in clockwise order. Then you can calculate internal angles:

Angle[i] =  Pi + ArcTan2(V[i] x V[i+1], V[i] * V[i+1]) 

(crossproduct and dotproduct of incoming and outgoing vectors for every vertex)

or

Angle[i] = Pi + ArcTan2( dx_in*dy_out-dx_out*dy_in, dx_in*dx_out+dy_in*dy_out2 )

Note: change plus sign after Pi to minus for anti-clockwise direction.

Edit:

Note that crossproduct and dotproduct are scalars, not vectors.

Example for your data:

dx1 = 5; dy1 = -15; dx2 = -15; dy2 = 5

Angle = Pi + ArcTan2(5*5-15*15, -5*15-5*15) = Pi - 2.11 radians ~ 59 degrees

Example for vectors:

(0,-1) (1,0) (L-curve)

Angle = Pi + ArcTan2(1, 0) =  270 degrees
like image 91
MBo Avatar answered Oct 24 '22 10:10

MBo