-1

I have a list of points (pixels) QList<QPoint> that represent a curve looking like a orthogonal polyline.

enter image description here

My task is to split this one to small straight lines (an instance of QList<QLineF>). In order to know the end of a previous subline and beginning of a next subline, I got to know which points are vertexes of polyline, that is, the points where sublines are intersected.

What would be the best way to figure out that some point is a vertex?

Nikita
  • 337
  • 1
  • 3
  • 12
  • Are you saying you have a list of points where some adjacent points are colinear and you want to find only the points that indicate a bend? – acraig5075 Jul 26 '18 at 06:46
  • In my opinion all points in a polyline are vertexes (vertices), so I would loop through the list of points and make a line starting at the current index and ending at the index+1 (so make sure not to iterate to the last element). If this does not match your idea, please ellaborate – Amfasis Jul 26 '18 at 06:46
  • @Amfasis Refined a question for you. – Nikita Jul 26 '18 at 10:04
  • 1
    @Nikita ok, I understand it now, but you already found the answer ;-) for optimal understanding I would draw little dots on the image you added – Amfasis Jul 26 '18 at 10:31

1 Answers1

0

I've found the answer by myself. It doesn't seem to be convenient and clear, nevertheless it works out.

QList<QPoint> vertexes;

for (int i = 2; i < points.size(); i++)
{
    bool xChanged = points[i-2].x() != points[i].x();
    bool yChanged = points[i-2].y() != points[i].y();

    if (xChanged && yChanged)
        vertexes.append(points[i-1]);
}

vertexes.prepend(points.first());
vertexes.append(points.last());

We check two points every loop iteration - the current point and the point two points ago. If their X and Y aren't equal, it means that curve change its direction and the point between them is a vertex.

Nikita
  • 337
  • 1
  • 3
  • 12