reliably determine if a shape is 2D.

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: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

reliably determine if a shape is 2D.

Post by sliptonic »

I've got a function that tests if a hole is drillable. It acts differently if it is evaluating a solid object rather than a 2D object. In one case it evaluates faces, in the other it only looks at edges.

I've been looking at the ZLength of the shape boundbox to see if it's greater than 0 but there are cases where a 2D object boundbox meets that criteria.

What's a reliable way to tell if my shape is 2D?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: reliably determine if a shape is 2D.

Post by DeepSOIC »

In c++, OCC offers a routine to find plane. AFAIK it uses edges, so it will probably tell you that a sphere is a 2d object. I don't think it is exposed to python...
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: reliably determine if a shape is 2D.

Post by yorik »

DraftGeomUtils.isPlanar(shape) does it.
Basically fin d a normal for the shape (from any 3 non-aligned vertices), th project all other vertices on that normal. If any of them gives any length (ie. it is not strictly perpendicular to the normal), then the shape is not planar.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: reliably determine if a shape is 2D.

Post by DeepSOIC »

yorik wrote:Basically fin d a normal for the shape (from any 3 non-aligned vertices), ....
What about circles? They have only 1 vertex...
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: reliably determine if a shape is 2D.

Post by yorik »

yes, but circles will always be planar...
I wonder if it would be possible to have a cyclic (one vertex) spline that is not planar?
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: reliably determine if a shape is 2D.

Post by Chris_G »

Hi Yorik,
yorik wrote:I wonder if it would be possible to have a cyclic (one vertex) spline that is not planar?
Yes, it is :
BSpline.jpg
BSpline.jpg (26.09 KiB) Viewed 925 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: reliably determine if a shape is 2D.

Post by yorik »

CQFD :D thanks!
Post Reply