Line clipping algorithms

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
MRx
Posts: 319
Joined: Wed Jul 08, 2020 5:59 am
Location: Tainan / Taiwan

Line clipping algorithms

Post by MRx »

Hi,

does anyone know are there any line clipping algorithms implemented in FreeCAD or in the connected libraries?

There are a few options, I need one for the outline path generation.
https://forum.freecadweb.org/viewtopic. ... 69#p549935

I want to clip every single path as soon as it leaves a defined area / stock (maybe plus/minus some offset)

https://en.wikipedia.org/wiki/Line_clipping

----

Problem solved, Zheng Lei directed me to Path.Area which already has an implementation for this.

just something like that:
Part.show(Path.Area().add([FreeCAD.ActiveDocument.Sketch002.Shape, FreeCAD.ActiveDocument.Sketch.Shape], op=2).getShape())
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Line clipping algorithms

Post by onekk »

line clipping is somewhat different, from Path.Area.

You could find the intersection of the lines and rearrange start and ending points (I intend it using scripting).

same for extend, there are also some OOCT methods that do such things.

Code: Select all


from draftgeoutils.intersections import findIntersection

np_a = line1
np_a = line2

cc = findIntersection(np_a, np_b, True, True)

# this is a list of intersection points

Hope it helps

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply