extending a segment

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
sliptonic
Veteran
Posts: 3453
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

extending a segment

Post by sliptonic »

Say I've got a line segment L created with something like Part.makeLine(v1,v2)

How do I add (or subtract) some arbitrary amount to one end? For example add 2mm to the v1 end?
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: extending a segment

Post by TheMarkster »

You mean find the direction and the coordinates needed for the new end of the line? I think this works.

Code: Select all

v1 = App.Vector(0,0,0)
v2 = App.Vector(10,10,5)
l1 = Part.makeLine(v1,v2)
Part.show(l1)
dir1 = (v2-v1).normalize()
#add 3.14 mm to line
v3 = App.Vector(dir1.multiply(l1.Length+3.14))
l2 = Part.makeLine(v2,v3)
Part.show(l2)
User avatar
sliptonic
Veteran
Posts: 3453
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: extending a segment

Post by sliptonic »

Awesome! Thank you.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: extending a segment

Post by TheMarkster »

It occurs to me if v1 is not on the origin another addition might be needed to get v3 correctly offset from v1.
Post Reply