Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interior angles of irregular polygon with angles > 180

I'm trying to calculate the values shown in the picture in red i.e. the interior angles.

I've got an array of the points where lines intersect and have tried using the dot-product but it only returns the smallest angles. I need the full range of internal angles (0-359) but can't seem to find much that meets this criteria.

arrow

like image 238
2 revsS.Lott Avatar asked Oct 15 '25 08:10

2 revsS.Lott


1 Answers

Assuming your angles are in standard counterclockwise format, the following should work:

void angles(double points[][2], double angles[], int npoints){
    for(int i = 0; i < npoints; i++){
        int last = (i - 1 + npoints) % npoints;
        int next = (i + 1) % npoints;
        double x1 = points[i][0] - points[last][0];
        double y1 = points[i][1] - points[last][1];
        double x2 = points[next][0] - points[i][0];
        double y2 = points[next][1] - points[i][1];
        double theta1 = atan2(y1, x1)*180/3.1415926358979323;
        double theta2 = atan2(y2, x2)*180/3.1415926358979323;
        angles[i] = (180 + theta1 - theta2 + 360);
        while(angles[i]>360)angles[i]-=360;
    }
}

Obviously, if you are using some sort of data structure for your points, you will want to replace double points[][2] and references to it with references to your data structure.

like image 119
k_g Avatar answered Oct 16 '25 20:10

k_g



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!