PDA

View Full Version : What really is a QPolygon...

giusepped
8th January 2009, 03:48
Suppose the following code I supposed to do a union of polyogn

QPolygonF f,g;

f<<QPointF(1,1)<<QPointF(10,29);
g<<QPointF(100,100)<<QPointF(10,290);

qSort(f.begin(),f.end(),lessThanPoint);
qSort(g.begin(),g.end(),lessThanPoint);
qDebug()<< f.united(g);

Why I get the following result:

QPolygonF(QPointF(1, 1)QPointF(1, 1)QPointF(10, 29)QPointF(1, 1)QPointF(10, 290)QPointF(100, 100)QPointF(10, 290)QPointF(1, 1))

:confused:

I should have simply the union of the point (a polygon of 4 points).
Maybe I am missing something?
G

aamer4yu
8th January 2009, 04:13
For your requirement you can use QPainter::drawPolyline

or you can see QPaintEngine::PolygonDrawMode

giusepped
8th January 2009, 04:56
I do not understand.
Actually, I wanna perform a merging of two curve obatained from two data set.
But: during the merging I would keep only those points who are the highest (I am supposing to draw the polygons on an xy plane).
There is a simple way in qt to merge two curves in this way?
G

wysota
8th January 2009, 08:44
Simply draw them both. One will cover the other and you will get what you wanted.

giusepped
8th January 2009, 08:48
Yes, you're right. I should study more...
Anyway, if the polygons really represent curve, I have to dela with extremes...

QPolygonF MyPlot::combine( QPolygonF &serie1, QPolygonF &serie2)
{

QPolygonF p1(serie1);
QPolygonF p2(serie2);
p1.prepend(QPointF(serie1.first().x(),0));
p1.append(QPointF(serie1.last().x(),0));
p2.prepend(QPointF(serie2.first().x(),0));
p2.append(QPointF(serie2.last().x(),0));

QPolygonF temp(p1.united(p2));

QPointF first,last;

qSort(temp.begin(),temp.end(),lessThanPoint);

first = temp.first();
last = temp.last();
QPolygonF t(temp);

t.resize(t.size()-2);

t.append(last);

return t;
}

giusepped
9th January 2009, 08:11
I am quite stucked at this problem...the previous code does not work.
The problem is depicted in the figure.
There is a way to merge two curves or polygon and picks the envelope?
Regards

wysota
9th January 2009, 08:28
It's not an easy math problem so I wouldn't expect there to be a ready function for it in Qt.

giusepped
9th January 2009, 09:58
Actually, the union of polygons works quite well with QPOlygonF::united(), and
I expected that a similar function was available also for polylines.
The problem is that after the union, the points are not ordered in the right way....
It should be enough to have a way to open the polygon, i.e. eliminating the segment which lies on the x axis....:crying:

wysota
9th January 2009, 18:55
Have you tried using QPainterPath? Maybe you'll have more luck with it.

giusepped
10th January 2009, 01:59
I have no idea at all how to use it.
If you some suggestion, I will appreciate very much....
G

wysota
10th January 2009, 08:53
Add primitives to it. You can also unite it. There is a paragraph in the reference (Composing a QPainterPath) that might be helpful.

giusepped
14th January 2009, 06:57
I tried, but the problem is always the same.
After the union of paths, the points order is arbitary and for this reason is quite difficult to convert the path to a curve in the 2D-plane.
(For instance, the union of Polygons use the united function of QPainterPath).
G