WildWolfCJ wrote: ↑Wed Dec 20, 2023 2:55 am
I don’t understand how the unclosed polyline in the attachment can be manually generated by magenta closed outline, please check the attachment,
OK, wow, that explains a lot.
We both are thus at the two opposite extremes of the development spectrum.
OQ is the QCAD 2 key keyboard shortcut sequence for the tool under menu
Draw .. Polyline .. Offset.
- In QCAD GUI mode open a file with an open ended polyline or start a new file and draw a new polyline.
- Create a new layer for the offset shape, LineWeight 0.00mm and a different color may be handy. (= Current on creation)
- Type the key
O, release and then key
Q or whatever keys that are on a non-Latin keyboard.
- In the Options Toolbar enter an offset value (Half the pen size) and opt for: Single offset, Offset Whole the Polyline, Round Joints.
Clipping or not is less important with trivial cases, the outcome may vary and you can activate/deactivate that in preview mode.
- Indicate near your line-art and an offset preview will be shown.
- If satisfactory then create it with clicking left once.
- Indicate near the other side of the same line-art and click left again.
- Terminate the offset tool with a right click. (Or with escape, or with the key-sequence
QQ)
You now have an offset at both sides of the line-art.
For the round butt-endings we need another GUI tool: menu
Draw .. Arc .. 2 Points and Angle (Keyboard shortcut =
A2)
- In the Options Toolbar enter an angle value of 180 degrees.
Orientation depends on what point you will indicate first and you can alter that in preview mode after the first arc endpoint is given.
- Indicated two matching endpoints of the offset shapes, use a proper orientation so that the arc bulges outwards.
- Repeat this for the opposite endings.
- Terminate the arc tool with a right click.
You now have 4 independent drawing entities: 2 offset shapes and 2 arcs.
For merging these we need to select them all 4, if 'free-floating' you can also double-click left near one of the shapes.
Now activate the GUI tool under menu
Draw .. Polyline .. Polyline from Selection(
OC).
The selection is turned into a single polyline, see selection in the Property Editor. (Re-select if if it was not)
When selected this should report to be (logically) closed in the Property Editor.
Otherwise you need to verify what went wrong for it not to form a single and perfectly closed contour.
For that verify the position of the red and dark-blue end markers if selected, zoom in on them to have a closer look.
- - - - - -
For a script exploiting
RPolygonOffset(..) there is no human to indicated sides ... To verify results ... To do whatever.
The inner or outer side of arbitrary line-art is an unknown fact and even methods to determinate that may return ambiguous answers.
We can fall back on forcing the side parameter (
RS.LeftHand,
RS.RightHand) and pos =
RVector.invalid.
I opted for twice
RS.LeftHand reversing a clone of the base shape in between, resulting in two (arrays of)
RPolyline shapes.
Remind that these are low level mathematical representations, there is nothing for you to view in a document.
A 180 degree arc is nothing more than setting the last bulge factor of an open ended
RPolyline shape to
tan(180°/4)=1.0 and because the two shapes are pre-oriented I can simply append the second to the first.
If the single
RPolyline is geometrically closed it is converted to a logical closed
RPolyline and stored for later handling.
At this point I cast a copy to the drawing document in the GUI so that I can verify the outcome.
In fact, they are the magenta entities on layer 'Results'.
This all looks fairly straightforward ... But it isn't.
Using the GUI we humans can start over new if it didn't work out as expected.
What with none or more than one
RPolyline from
RPolygonOffset(..)?
Are they clean? Do they Include minute self-intersections, inversions of arcs and/or ... ?
What with minute differences at connection points between shapes. How good is 'almost' connected? How good can it be?
What if two endings are more than a pen apart for round butt-end?
How tolerant for small but unavoidable Floating Point errors, accumulated math flaws, loss of accuracy?
....
...
.
Every step of the process needs to be verified for what it produces and if that is valid or not. (Define what is valid
)
Each type of base entity is handled in a similar but specialized fashion.
Lines, Arcs, open ended Polylines, geometrically closed Polylines, Ellipses and their arcs, ....
Some methods rely on another.
Remark that when the endpoints of a single open entity come close enough you end up with an inner and outer contour instead of single outline.
See almost fully closed ellipse arc examples.
Busy ...
Regards,
CVH