Results 1 to 5 of 5

Thread: Inward/outward QPainterPath/polygon offset

  1. #1
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Inward/outward QPainterPath/polygon offset

    Hello all,

    Does Qt have the ability to generate inward/outward offset paths similar to what is shown in the image?

    If not, can anyone offer a lightweight solution?

    polygonOffset.jpg

    Thanks,
    Ben

  2. #2
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Inward/outward QPainterPath/polygon offset

    If not available, this would be a useful feature to add to QPainterPath. Note, offsets are not the same thing as scaling because they are done on a edge basis.

    I ended up computing the edge/wire offsets by using third party software. The result is shown below (note the slightly less bright dashed line).

    offsetExample.jpg

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Inward/outward QPainterPath/polygon offset

    Geometrically, this is equivalent to rolling a circle of radius equal to the offset distance along the curve and plotting the trajectory of the center of the circle. The problem is that the elements of a path can be both geometric (lines, arcs, rectangles, etc.) as well as parametric (cubic and quadratic Bezier curve) objects. Paths can also be convex, concave, closed, open, intersecting, connected and disconnected.

    So *if* you can compute the bounding exterior contour, then in principle you can compute an outer offset path. Computing an inner offset path would be much harder, I think, given all the possibilities.

    To complicate this, QPainterPath does not give you access to the bounding contour. The best you can get is pointAtPercent() and slopeAtPrecent(), and that doesn't really tell you anything about whether the point is on the outer boundary of a closed curve or on an interior element.
    Last edited by d_stranz; 28th September 2016 at 23:20.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Inward/outward QPainterPath/polygon offset

    The third party software I ended up using supports polygon and parametric types. It's actually the 2D portions of a full blown CAD engine.

    You can get the bounding contour of a QPainterPath with the toFillPolygon() method.

    It's easy to compute inward and outward offset shapes as long as they don't produce invalid geometry.

    Qt Code:
    1. QList<QPointF> points;
    2. QPolygonF polygon = outerArc.toFillPolygon();
    3. foreach(auto point, polygon)
    4. {
    5. points.push_back(point);
    6. }
    7. QList<QPointF> pointsResult;
    8. makeOffsetFace(points, -0.25*mMaxelSize, pointsResult);
    9. QPolygonF polygonOffset;
    10. foreach(auto point, pointsResult)
    11. {
    12. polygonOffset << point;
    13. }
    14. if(!polygonOffset.isEmpty())
    15. {
    16. mOuterFillPath.addPolygon(polygonOffset);
    17. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to brcain for this useful post:

    d_stranz (29th September 2016)

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Inward/outward QPainterPath/polygon offset

    You can get the bounding contour of a QPainterPath with the toFillPolygon() method.
    Ah, didn't realize that - good to know.

    What does "makeOffsetFace" do? If I were to guess, it would calculate the bisecting line between two adjacent polygon edges and move outward or inward along that line for the specified offset to find the new point for the outer or inner polygon, correct? I presume there is also a "handedness" rule that determines outward vs. inward as you move along the polygon in a clockwise or counterclockwise direction.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Point in a Polygon
    By jesse_mark in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2013, 01:49
  2. Points in Polygon
    By jesse_mark in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2012, 21:58
  3. QPainterPath::quadTo(...) calls QPainterPath::cubicTo(...) ?
    By brucelamond in forum Qt Programming
    Replies: 0
    Last Post: 29th April 2011, 00:30
  4. pixmap to polygon
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2009, 10:02
  5. Rotating the polygon
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 4th September 2008, 01:41

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.