## 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.

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.

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

### Re: reliably determine if a shape is 2D.

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.

yorik wrote:Basically fin d a normal for the shape (from any 3 non-aligned vertices), ....
What about circles? They have only 1 vertex...
yorik
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

### Re: reliably determine if a shape is 2D.

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

### Re: reliably determine if a shape is 2D.

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 (26.09 KiB) Viewed 99 times
yorik
Posts: 8570
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

CQFD thanks!