No easy way to get start and end points of straight edge?

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
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

No easy way to get start and end points of straight edge?

Post by DeepSOIC »

Hi!
There used to be an easy way to obtain coordinates of endpoints of a linear edge:

Code: Select all

edge.Curve.StartPoint
edge.Curve.EndPoint
Now they are gone. So I see three ways of doing it now, which are quite a bit uglier:

Code: Select all

edge.Vertexes[0].Point
edge.Curve.value(edge.FirstParameter)
edge.valueAt(edge.FirstParameter)
The first one is ugly because I'm not sure if Vertexes[0] is always the vertex that corresponds to FirstParameter. The second and the third ones are substantially longer code, and it feels like it will do unnecessary computations under the hood (probably doesn't matter).

So I ask: give me a straightforward way to convert a linear edge into a LineSegment, not Line.
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: No easy way to get start and end points of straight edge?

Post by Chris_G »

Code: Select all

edge.toNurbs().Edges[0].Curve.StartPoint
edge.toNurbs().Edges[0].Curve.EndPoint
:mrgreen:
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: No easy way to get start and end points of straight edge?

Post by DeepSOIC »

Chris_G wrote:

Code: Select all

edge.toNurbs().Edges[0].Curve.StartPoint
edge.toNurbs().Edges[0].Curve.EndPoint
:mrgreen:
:lol:
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: No easy way to get start and end points of straight edge?

Post by DeepSOIC »

I just patched up Lattice's LinearArray and PolarArray that were broken because of this.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: No easy way to get start and end points of straight edge?

Post by wmayer »

There used to be an easy way to obtain coordinates of endpoints of a linear edge:
No that's not correct. With the old behaviour where from an edge a LineSegment instead of an infinite Line was returned it's not necessarily true that the segment's start point is coincident the edge's start vertex because it also depends on the edge's orientation.

A reliable way to determine the start vertex is to check its orientation: if it is set to forward then it's the start vertex, if it's set to reversed then it's the end vertex.

For more information have a look at this thread: https://forum.freecadweb.org/viewtopic.php?t=18204

Based on Yorik's example I have put together this code snippet which must be tested with 0.16 (or the setting to activate the old behaviour)

Code: Select all

b = Part.makeBox(2,2,2)
b.Edges[2].Orientation # => Reversed
b.Edges[2].Curve # => <Line (0,2,0) (0,2,2) >
b.Edges[2].Vertexes[0].Point, b.Edges[2].Vertexes[0].Orientation # => (Vector (0.0, 2.0, 2.0), 'Forward')
b.Edges[2].Vertexes[1].Point, b.Edges[2].Vertexes[1].Orientation # => (Vector (0.0, 2.0, 0.0), 'Reversed')
In this case the line's start point is (0,2,0) but the edge's start vertex is (0,2,2)
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: No easy way to get start and end points of straight edge?

Post by wmayer »

The class TopExp of OCC provides two static methods FirstVertex and LastVertex to get an edge's first or last vertex. The methods accept a second parameter to take the edge's orientation into account or not.

Code: Select all

  //! Returns the Vertex of orientation FORWARD in E. If
  //! there is none returns a Null Shape.
  //! CumOri = True : taking account the edge orientation
  Standard_EXPORT static TopoDS_Vertex FirstVertex (const TopoDS_Edge& E, const Standard_Boolean CumOri = Standard_False);
  
  //! Returns the Vertex of orientation REVERSED in E. If
  //! there is none returns a Null Shape.
  //! CumOri = True : taking account the edge orientation
  Standard_EXPORT static TopoDS_Vertex LastVertex (const TopoDS_Edge& E, const Standard_Boolean CumOri = Standard_False);
I think the very best would be to add these two methods to our topo edge Python wrapper.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: No easy way to get start and end points of straight edge?

Post by DeepSOIC »

wmayer wrote:The class TopExp of OCC provides two static methods FirstVertex and LastVertex to get an edge's first or last vertex. The methods accept a second parameter to take the edge's orientation into account or not.
I think the very best would be to add these two methods to our topo edge Python wrapper.
Sounds good to me :D But for Lattice, I am sticking to edge.valueAt(edge.FirstParameter), because I want to keep supporting FC v0.16.
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: No easy way to get start and end points of straight edge?

Post by damian »

Code: Select all

edge.firstVertex(True)
edge.lastVertex(True)
very useful
Post Reply