Results 1 to 12 of 12

Thread: What really is a QPolygon...

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default What really is a QPolygon...

    Suppose the following code I supposed to do a union of polyogn
    Qt Code:
    1.  
    2. f<<QPointF(1,1)<<QPointF(10,29);
    3. g<<QPointF(100,100)<<QPointF(10,290);
    4.  
    5.  
    6. qSort(f.begin(),f.end(),lessThanPoint);
    7. qSort(g.begin(),g.end(),lessThanPoint);
    8. qDebug()<< f.united(g);
    To copy to clipboard, switch view to plain text mode 
    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))



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

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    For your requirement you can use QPainter::drawPolyline
    or you can see QPaintEngine::PolygonDrawMode

  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What really is a QPolygon...

    Simply draw them both. One will cover the other and you will get what you wanted.

  5. #5
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    Yes, you're right. I should study more...
    Anyway, if the polygons really represent curve, I have to dela with extremes...
    Qt Code:
    1. QPolygonF MyPlot::combine( QPolygonF &serie1, QPolygonF &serie2)
    2. {
    3.  
    4. QPolygonF p1(serie1);
    5. QPolygonF p2(serie2);
    6. p1.prepend(QPointF(serie1.first().x(),0));
    7. p1.append(QPointF(serie1.last().x(),0));
    8. p2.prepend(QPointF(serie2.first().x(),0));
    9. p2.append(QPointF(serie2.last().x(),0));
    10.  
    11. QPolygonF temp(p1.united(p2));
    12.  
    13. QPointF first,last;
    14.  
    15.  
    16. qSort(temp.begin(),temp.end(),lessThanPoint);
    17.  
    18. first = temp.first();
    19. last = temp.last();
    20. QPolygonF t(temp);
    21.  
    22. t.resize(t.size()-2);
    23.  
    24.  
    25. t.append(last);
    26.  
    27.  
    28. return t;
    29. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    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
    Attached Images Attached Images

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What really is a QPolygon...

    It's not an easy math problem so I wouldn't expect there to be a ready function for it in Qt.

  8. #8
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    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....

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What really is a QPolygon...

    Have you tried using QPainterPath? Maybe you'll have more luck with it.

  10. #10
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    I have no idea at all how to use it.
    If you some suggestion, I will appreciate very much....
    G

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What really is a QPolygon...

    Add primitives to it. You can also unite it. There is a paragraph in the reference (Composing a QPainterPath) that might be helpful.

  12. #12
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What really is a QPolygon...

    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

Similar Threads

  1. Replies: 2
    Last Post: 24th January 2009, 08:11
  2. QPolygon rotate
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2007, 11:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.