Skip to content

Commit

Permalink
Fix orientation of "vertex" geomtransform (#5213)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorissette authored and tbonfort committed Feb 24, 2016
1 parent 4238420 commit 9b93019
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions mapgeomtransform.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,30 @@ double calcOrientation(pointObj *p1, pointObj *p2)

double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3)
{
double theta1,theta2;
theta1 = atan2(p1->x-p2->x,p1->y-p2->y);
if(theta1<0) theta1 += MS_2PI;
theta2 = atan2(p3->x-p2->x,p3->y-p2->y);
if(theta2<0) theta2 += MS_2PI;
return MS_RAD_TO_DEG*((theta1+theta2)/2.0);
pointObj p1n;
double dx12, dy12, dx23, dy23, l12, l23;

/* We treat both segments as vector 1-2 and vector 2-3 and
* compute their dx,dy and length
*/
dx12 = p2->x - p1->x;
dy12 = p2->y - p1->y;
l12 = sqrt(dx12*dx12 + dy12*dy12);
dx23 = p3->x - p2->x;
dy23 = p3->y - p2->y;
l23 = sqrt(dx23*dx23 + dy23*dy23);

/* Normalize length of vector 1-2 to same as length of vector 2-3 */
if (l12 > 0.0)
{
p1n.x = p2->x - dx12*(l23/l12);
p1n.y = p2->y - dy12*(l23/l12);
}
else
p1n = *p2; /* segment 1-2 is 0-length, use segment 2-3 for orientation */

/* Return the orientation defined by the sum of the normalized vectors */
return calcOrientation(&p1n, p3);
}

/*
Expand Down

0 comments on commit 9b93019

Please sign in to comment.