Two line intersection in 3d

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Two line intersection in 3d

Post by Mark Szlazak »

I can't seem to find a two line intersection function in FreeCAD. I would like to use it on Part edges in my scripts.
Do i need to make my own?

http://mathforum.org/library/drmath/view/63719.html
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Two line intersection in 3d

Post by ickby »

You can use the common function, which results in a vertex at the intersection point if both intersect. Or use distToShape to get the zero distance point.
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: Two line intersection in 3d

Post by damian »

ickby wrote:You can use the common function
I think you have better result with section function

Code: Select all

section = edgeA.section(edgeB)
point = section.Vertexes[0].Point
or

Code: Select all

distance = edgeA.distToShape(edgeB)
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Two line intersection in 3d

Post by Mark Szlazak »

damian wrote:
ickby wrote:You can use the common function
I think you have better result with section function

Code: Select all

section = edgeA.section(edgeB)
point = section.Vertexes[0].Point
or

Code: Select all

distance = edgeA.distToShape(edgeB)
Oops, I should have said lines or vector directions defined by the end points of edges. This means that they are infinite. Functions like distToShape would not work.
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: Two line intersection in 3d

Post by damian »

damian wrote:Oops, I should have said lines or vector directions defined by the end points of edges
Oops, perhaps you are looking for something like this

Code: Select all

>>> l=Part.Line(App.Vector(0,0,0),App.Vector(10,0,0))
>>> ll=Part.Line(App.Vector(5,5,0),App.Vector(5,-5,0))
>>> l.intersect(ll)
[<Point (5,0,0) >]
jidoeuf
Posts: 43
Joined: Sun Mar 01, 2015 4:06 pm

Re: Two line intersection in 3d

Post by jidoeuf »

Look at Flamingo WB add-on, the path tool in Frame toolbox.
It creates a Dwire object connecting together, with the shortest path rule, all selected edges.
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Two line intersection in 3d

Post by Mark Szlazak »

jidoeuf wrote:Look at Flamingo WB add-on, the path tool in Frame toolbox.
It creates a Dwire object connecting together, with the shortest path rule, all selected edges.
It's not clear to me why i would do this given the various functions already built into freeCAD to do this that have already been posted. Can you please explain?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Two line intersection in 3d

Post by yorik »

Code: Select all

DraftGeomUtils.findIntersection()
Mark Szlazak
Posts: 439
Joined: Tue Apr 04, 2017 6:06 pm
Location: SF Bay Area, California

Re: Two line intersection in 3d

Post by Mark Szlazak »

On a related topic, is there a fast point/finite line segment (edge) intersection test that just gives back a true or false but does not proceed to calculate the intersection location?
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Two line intersection in 3d

Post by mario52 »

hi

Code: Select all

# 2. Solution using DraftGeomUtils
import DraftGeomUtils
s = FreeCADGui.Selection.getSelection()
L1 = s[0]
L2 = s[1]
v = DraftGeomUtils.findIntersection(L1.Shape.Edges[0],L2.Shape.Edges[0])

print(v) # [Vector (-1.3432017072221727, 0.28294823146762915, 0.0)]
print(v[0]) # Vector (-1.3432017072221727, 0.28294823146762915, 0.0)
print(v[0].x) # -1.3432017072221727
print(v[0].y) # 0.28294823146762915
print(v[0].z)# 0.0
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply