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
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
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
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 22: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.
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:
QList<QPointF> points; foreach(auto point, polygon) { points.push_back(point); } QList<QPointF> pointsResult; makeOffsetFace(points, -0.25*mMaxelSize, pointsResult); QPolygonF polygonOffset; foreach(auto point, pointsResult) { polygonOffset << point; } if(!polygonOffset.isEmpty()) { mOuterFillPath.addPolygon(polygonOffset); }To copy to clipboard, switch view to plain text mode
d_stranz (29th September 2016)
Ah, didn't realize that - good to know.You can get the bounding contour of a QPainterPath with the toFillPolygon() method.
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.
Bookmarks