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?
reliably determine if a shape is 2D.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- 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.
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...
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.
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
- 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.
What about circles? They have only 1 vertex...yorik wrote:Basically fin d a normal for the shape (from any 3 non-aligned vertices), ....
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?
I wonder if it would be possible to have a cyclic (one vertex) spline that is not planar?
Re: reliably determine if a shape is 2D.
Hi Yorik,
Yes, it is :yorik wrote:I wonder if it would be possible to have a cyclic (one vertex) spline that is not planar?
Re: reliably determine if a shape is 2D.
CQFD thanks!