discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

center() as transformation function

JC
Jesse Campbell
Thu, Sep 19, 2024 3:33 PM

Is there a generic center() function in OpenSCAD to center any shape?

Such as: center(){ cube(5); }

Instead of: cube(5, center=true);

Is there a generic center() function in OpenSCAD to center any shape? Such as: center(){ cube(5); } Instead of: cube(5, center=true);
PK
Peter Kriens
Thu, Sep 19, 2024 4:55 PM

In BOSL2 you can use attach() to use any of the standard 25 anchors and position the children relative to the parent shape. E.g. attach(TOP, CENTER) will put the cube in the middle of the top plane of the current shape, note half deep since CENTER is the center of the child cube.

If you do attach(TOP,BOTTOM) the cube will sit fully on top of the current shape, bottom fixed to the top of the parent shape. To make it even better, you can then also specify where on the plane the cube should attach with align. Ie you attach the cube aligned on the LEFT side or even LEFT+BACK corner.

This also works most if the times for none rectangular shapes where sides are angled or curved.

The only reason I’m still on openscad is this relative addressing. Awesome!

Sent from my iPad

On 19 Sep 2024, at 17:33, Jesse Campbell via Discuss discuss@lists.openscad.org wrote:

Is there a generic center() function in OpenSCAD to center any shape?

Such as: center(){ cube(5); }

Instead of: cube(5, center=true);


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

In BOSL2 you can use attach() to use any of the standard 25 anchors and position the children relative to the parent shape. E.g. attach(TOP, CENTER) will put the cube in the middle of the top plane of the current shape, note half deep since CENTER is the center of the child cube. If you do attach(TOP,BOTTOM) the cube will sit fully on top of the current shape, bottom fixed to the top of the parent shape. To make it even better, you can then also specify where on the plane the cube should attach with align. Ie you attach the cube aligned on the LEFT side or even LEFT+BACK corner. This also works most if the times for none rectangular shapes where sides are angled or curved. The only reason I’m still on openscad is this relative addressing. Awesome! Sent from my iPad > On 19 Sep 2024, at 17:33, Jesse Campbell via Discuss <discuss@lists.openscad.org> wrote: > > Is there a generic center() function in OpenSCAD to center any shape? > > Such as: center(){ cube(5); } > > Instead of: cube(5, center=true); > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org