Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol orientation problem using GEOMTRANSFORM "vertices" with ANGLE AUTO #5213

Closed
wants to merge 1 commit into from
Closed

Symbol orientation problem using GEOMTRANSFORM "vertices" with ANGLE AUTO #5213

wants to merge 1 commit into from

Conversation

tbonfort
Copy link
Member

@tbonfort tbonfort commented Jan 4, 2016

We tried to use GEOMTRANSFORM "vertices" with ANGLE AUTO to display a directional arrow on each vertex of a GPS track and noticed that the current version of calcMidAngle() sometimes results in symbols with the reversed orientation.

Here is an illustration of the problem using the msautotest/renderers/geomtransform-vertex.map in which the vertex symbols from the original test case are replaced by arrow heads. The blue dot marks the beginning of the line, and you'll notice that the arrow heads along the lines are not always in the right direction:
ttt-before2

The correct result would be this:
ttt

Here is a new version of calcMidAngle() that produces the corrected image above. The mathematicians around the room are welcome to propose a more optimal method.

double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3)
{
  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);
}

I'll try to produce a proper pull request with the fix and the necessary updates to msautotest but since I'm a still git-challenged, it may take some time before I get to that so I thought I should file this here in case another dev wants to grab and commit the fix.

@tbonfort
Copy link
Member

tbonfort commented Feb 24, 2016

rebased into branch-7-0 in 9b93019

@tbonfort tbonfort closed this Feb 24, 2016
@tbonfort tbonfort added this to the 7.0.1 milestone Feb 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants