is an Edges straight, get the direction

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
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

is an Edges straight, get the direction

Post by bernd »

Checked the methods which can be applied on an Edge ... There are dozens ...

Which is used best to get the information if an edge is straight and if it is straight which is it's direction?

The last one could just be done by subtracting the point vectors, AFAIK.

bernd
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: is an Edges straight, get the direction

Post by microelly2 »

transform it to a nurbs and check whether all poles ar collinear.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: is an Edges straight, get the direction

Post by openBrain »

Here my proposal (considering edge is stored in "myEdge" variable) :

Code: Select all

myEdgeVector = myEdge.lastVertex().Point-myEdge.firstVertex().Point
myEdgeDirection = (myEdgeVector + App.Vector()).normalize()
myEdgeIsStraight = ( sum([a**2 for a in myEdgeVector]) == myEdge.Length**2 )
HTH
User avatar
brst
Posts: 87
Joined: Thu Apr 18, 2019 10:11 am
Location: Germany

Re: is an Edges straight, get the direction

Post by brst »

Code: Select all

p = Part.read("path")
e = Part.Edges[0]
if type(e.Curve) == Part.Line:
   print("Edge is a line!")
This will just work for actual lines, but not for Circles or Part.ArcOfCircle that are approximately a line. Then you could go for np.isclose(edge.Length, diffVector, eps) and checking for a large enough radius.
FreeCAD rookie
Post Reply