reliably determine if a shape is 2D.

Need help, or want to share a macro? Post here!
sliptonic
Posts: 599
Joined: Tue Oct 25, 2011 10:46 pm

reliably determine if a shape is 2D.

Postby sliptonic » Sun Mar 19, 2017 3:11 pm

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?
DeepSOIC
Posts: 4507
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: reliably determine if a shape is 2D.

Postby DeepSOIC » Sun Mar 19, 2017 4:39 pm

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
Site Admin
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: reliably determine if a shape is 2D.

Postby yorik » Sun Mar 19, 2017 4:48 pm

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.
DeepSOIC
Posts: 4507
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: reliably determine if a shape is 2D.

Postby DeepSOIC » Sun Mar 19, 2017 4:53 pm

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
Site Admin
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: reliably determine if a shape is 2D.

Postby yorik » Mon Mar 20, 2017 2:08 pm

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
Posts: 354
Joined: Tue Dec 31, 2013 4:10 pm
Location: France

Re: reliably determine if a shape is 2D.

Postby Chris_G » Mon Mar 20, 2017 2:54 pm

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 99 times
User avatar
yorik
Site Admin
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: reliably determine if a shape is 2D.

Postby yorik » Tue Mar 21, 2017 2:56 pm

CQFD :D thanks!