feature request: centering axes independently

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

feature request: centering axes independently

Whosawhatsis
It would be nice if OpenSCAD allowed you to select whether or not to center squares and cubes on each axis independently. Here's the syntax I suggest:

cube(10, center = [true, true, false]);


This should create a 10mm cube sitting on the center of the X/Y plane. I know there are ways to do this using translate, but it would make the code more elegant and easier to edit.


Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

nophead
That's good but it allows only 8 positions. If it was  cube(10, center = [0.5,0.5,0]);  one could select any point within the cube to be the centre.

On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:
It would be nice if OpenSCAD allowed you to select whether or not to center squares and cubes on each axis independently. Here's the syntax I suggest:

cube(10, center = [true, true, false]);


This should create a 10mm cube sitting on the center of the X/Y plane. I know there are ways to do this using translate, but it would make the code more elegant and easier to edit.



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Giles Bathgate-2

You can just do

translate([0.5,0.5,0.5])cube([10,10,10],center=true);

is the feature really worthwhile? It is less to type and should be a bit faster to evaluate.

Regards

Giles

On Mar 25, 2012 2:25 PM, "nop head" <[hidden email]> wrote:
>
> That's good but it allows only 8 positions. If it was  cube(10, center = [0.5,0.5,0]);  one could select any point within the cube to be the centre.
>
> On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:
>>
>> It would be nice if OpenSCAD allowed you to select whether or not to center squares and cubes on each axis independently. Here's the syntax I suggest:
>>
>> cube(10, center = [true, true, false]);
>>
>>
>> This should create a 10mm cube sitting on the center of the X/Y plane. I know there are ways to do this using translate, but it would make the code more elegant and easier to edit.
>>
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Whosawhatsis
I think what he meant was that the vector would determine the center point as a percentage of the corresponding dimensions. There is currently no way to do this without either duplicating the code used to specify that dimension (a single scalar in these examples, but it could easily be a complicated algorithm) or creating a variable that will only be used twice and makes it harder to track down the relevant bit of code.

On Sunday, March 25, 2012 at 6:32 AM, Giles Bathgate wrote:

You can just do

translate([0.5,0.5,0.5])cube([10,10,10],center=true);

is the feature really worthwhile? It is less to type and should be a bit faster to evaluate.

Regards

Giles

On Mar 25, 2012 2:25 PM, "nop head" <[hidden email]> wrote:
>
> That's good but it allows only 8 positions. If it was  cube(10, center = [0.5,0.5,0]);  one could select any point within the cube to be the centre.
>
> On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:
>>
>> It would be nice if OpenSCAD allowed you to select whether or not to center squares and cubes on each axis independently. Here's the syntax I suggest:
>>
>> cube(10, center = [true, true, false]);
>>
>>
>> This should create a 10mm cube sitting on the center of the X/Y plane. I know there are ways to do this using translate, but it would make the code more elegant and easier to edit.
>>
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

_______________________________________________
OpenSCAD mailing list

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

chrysn
In reply to this post by nophead
On Sun, Mar 25, 2012 at 02:25:26PM +0100, nop head wrote:
> On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:
>
> > cube(10, center = [true, true, false]);
>
> That's good but it allows only 8 positions. If it was  cube(10, center =
> [0.5,0.5,0]);  one could select any point within the cube to be the centre.

i'd like to have center=[true, true, false] as it integrates better with
the classical semantics of center, and having center=x equal center=[x,
x, x] should cause no confusion.

if my understanding of booleans in openscad is correct, it *might* be
possible to make center accept floats in addition to that, and treat
true as 0.5, false as 0, and use them as fractional negative offsets.
that interpretation is non-obvious, though, judging from the fact that
i'd read your cube(10, center=[0.5, 0.5, 0.5]) as a cube at [-5, -5,
-5], while giles read it as at [0.5, 0.5, 0.5].

regards
chrysn

--
To use raw power is to make yourself infinitely vulnerable to greater powers.
  -- Bene Gesserit axiom

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Whosawhatsis
I thought of that, but the most logical way to set center fractionally would make true = 0 and false = 1. That way you would center on the opposite corner using center = -1. Of course, if you made center = 2 center on the opposite corner instead, your suggestion would work, but the syntax would not be as logical.

On Sunday, March 25, 2012 at 7:10 AM, chrysn wrote:

On Sun, Mar 25, 2012 at 02:25:26PM +0100, nop head wrote:
On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:

cube(10, center = [true, true, false]);

That's good but it allows only 8 positions. If it was cube(10, center =
[0.5,0.5,0]); one could select any point within the cube to be the centre.

i'd like to have center=[true, true, false] as it integrates better with
the classical semantics of center, and having center=x equal center=[x,
x, x] should cause no confusion.

if my understanding of booleans in openscad is correct, it *might* be
possible to make center accept floats in addition to that, and treat
true as 0.5, false as 0, and use them as fractional negative offsets.
that interpretation is non-obvious, though, judging from the fact that
i'd read your cube(10, center=[0.5, 0.5, 0.5]) as a cube at [-5, -5,
-5], while giles read it as at [0.5, 0.5, 0.5].

regards
chrysn

--
To use raw power is to make yourself infinitely vulnerable to greater powers.
-- Bene Gesserit axiom
_______________________________________________
OpenSCAD mailing list

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

nophead
In reply to this post by Whosawhatsis
Exactly, one ends up having to translate by half the length, or the full length all over the place.

On 25 March 2012 14:40, Whosawhatsis <[hidden email]> wrote:
I think what he meant was that the vector would determine the center point as a percentage of the corresponding dimensions. There is currently no way to do this without either duplicating the code used to specify that dimension (a single scalar in these examples, but it could easily be a complicated algorithm) or creating a variable that will only be used twice and makes it harder to track down the relevant bit of code.

On Sunday, March 25, 2012 at 6:32 AM, Giles Bathgate wrote:

You can just do

translate([0.5,0.5,0.5])cube([10,10,10],center=true);

is the feature really worthwhile? It is less to type and should be a bit faster to evaluate.

Regards

Giles

On Mar 25, 2012 2:25 PM, "nop head" <[hidden email]> wrote:
>
> That's good but it allows only 8 positions. If it was  cube(10, center = [0.5,0.5,0]);  one could select any point within the cube to be the centre.
>
> On 25 March 2012 14:05, Whosawhatsis <[hidden email]> wrote:
>>
>> It would be nice if OpenSCAD allowed you to select whether or not to center squares and cubes on each axis independently. Here's the syntax I suggest:
>>
>> cube(10, center = [true, true, false]);
>>
>>
>> This should create a 10mm cube sitting on the center of the X/Y plane. I know there are ways to do this using translate, but it would make the code more elegant and easier to edit.
>>
>>
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://rocklinux.net/mailman/listinfo/openscad
>>
>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>

_______________________________________________
OpenSCAD mailing list


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Alan Cox
On Sun, 25 Mar 2012 16:57:52 +0100
nop head <[hidden email]> wrote:

> Exactly, one ends up having to translate by half the length, or the full
> length all over the place

I could certainly appreciate the abilty to centre on an axis. A lot of
objects the centre is not trivial to work out.

For some stuff

        center() {
                object;
        }

would also be very very useful when building complex objects where parts
are rotated.

Alan

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Giles Bathgate-2

The centre() module sounds like a great idea. This could be useful for imported assets, in much the same respect as the resize() module is.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

chrysn
In reply to this post by Alan Cox
On Sun, Mar 25, 2012 at 10:11:55PM +0100, Alan Cox wrote:
> For some stuff
>
> center() {
> object;
> }
>
> would also be very very useful when building complex objects where parts
> are rotated.

how should that work? what's the "center" of a generic object? even if
we had bounding box information at hand (which, afaik, we don't),
cartesian bbox is not interchangable with rotation. if you have, for
example, a cone tilted around its original bbox center, how would you
find its new center?

regards
chrysn

--
To use raw power is to make yourself infinitely vulnerable to greater powers.
  -- Bene Gesserit axiom

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Giles Bathgate-2
> how should that work? what's the "center" of a generic object? even if
> we had bounding box information at hand (which, afaik, we don't),

While we don't have bbox information for use within AST evaluation we
do have bbox information at CSG evaluation time. Its simply a case of
enumerating all the points and finding xmin ymin zmin and xmax ymax zmax.

> cartesian bbox is not interchangable with rotation. if you have, for
> example, a cone tilted around its original bbox center, how would you
> find its new center?

The bounding box of a rotated cone would not conform to the tilted cone
in the sense that the bounding box would also be tilted. It would be a
new bounding box coplanar with the xy axis containing the extremities
of the tilted cone. This makes sense to me..

I have almost finished implementing this in RapCAD, you can see my
reference implementation when I check it in some time this evening.

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

chrysn
On Mon, Mar 26, 2012 at 08:37:53AM +0100, Giles Bathgate wrote:
> > cartesian bbox is not interchangable with rotation. if you have, for
> > example, a cone tilted around its original bbox center, how would you
> > find its new center?
>
> The bounding box of a rotated cone would not conform to the tilted cone
> in the sense that the bounding box would also be tilted. It would be a
> new bounding box coplanar with the xy axis containing the extremities
> of the tilted cone. This makes sense to me..

bounding-box-wise, this makes sense, but using that box for finding the
center produces results that are only intuitive to the user if he thinks
of the center as the *bounding box* center (which, apart from the people
concerned with the implementation, won't be many, i'm afraid).

to demonstrate what i put clumsily in words, code:

-----------

module straight()
{
        cylinder(r1=5, r2=0, h=20, center=true);
        % cube([10, 10, 20], center=true);
}

module oblique()
{
        rotate([0, 15, 0]) cylinder(r1=5, r2=0, h=20, center=true);
        % translate([-2, 0, -1]) cube([10, 10, 20], center=true);
}

straight();
translate([25, 0, 0]) oblique();

-----------

(the bbox isn't aligned trigonometrically perfect but optically, but
it's sufficiently precise to show the point)

that means that an object, once centred, will, when rotated, have a
different centre.  given that the more intuitive definition of the
center (the center of mass) doesn't exhibit those problems, i think
that's calling for trouble.

please don't get me wrong here, i don't want to deprecate your efforts,
just playing advocatus diaboli here :-)

best regards
chrysn

--
To use raw power is to make yourself infinitely vulnerable to greater powers.
  -- Bene Gesserit axiom

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

nophead
I don't think people would expect it be the centre of mass. For a cone that would be towards the bottom even when it was vertical. I think the bounding box is what people would expect, especially when it is a complex object, rather than a simple primitive that has an obvious geometric centre.

On 26 March 2012 09:03, chrysn <[hidden email]> wrote:
On Mon, Mar 26, 2012 at 08:37:53AM +0100, Giles Bathgate wrote:
> > cartesian bbox is not interchangable with rotation. if you have, for
> > example, a cone tilted around its original bbox center, how would you
> > find its new center?
>
> The bounding box of a rotated cone would not conform to the tilted cone
> in the sense that the bounding box would also be tilted. It would be a
> new bounding box coplanar with the xy axis containing the extremities
> of the tilted cone. This makes sense to me..

bounding-box-wise, this makes sense, but using that box for finding the
center produces results that are only intuitive to the user if he thinks
of the center as the *bounding box* center (which, apart from the people
concerned with the implementation, won't be many, i'm afraid).

to demonstrate what i put clumsily in words, code:

-----------

module straight()
{
       cylinder(r1=5, r2=0, h=20, center=true);
       % cube([10, 10, 20], center=true);
}

module oblique()
{
       rotate([0, 15, 0]) cylinder(r1=5, r2=0, h=20, center=true);
       % translate([-2, 0, -1]) cube([10, 10, 20], center=true);
}

straight();
translate([25, 0, 0]) oblique();

-----------

(the bbox isn't aligned trigonometrically perfect but optically, but
it's sufficiently precise to show the point)

that means that an object, once centred, will, when rotated, have a
different centre.  given that the more intuitive definition of the
center (the center of mass) doesn't exhibit those problems, i think
that's calling for trouble.

please don't get me wrong here, i don't want to deprecate your efforts,
just playing advocatus diaboli here :-)

best regards
chrysn

--
To use raw power is to make yourself infinitely vulnerable to greater powers.
 -- Bene Gesserit axiom

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: feature request: centering axes independently

Giles Bathgate-2
On 26 March 2012 09:19, nop head <[hidden email]> wrote:
> I don't think people would expect it be the centre of mass. For a cone that
> would be towards the bottom even when it was vertical. I think the bounding
> box is what people would expect, especially when it is a complex object,
> rather than a simple primitive that has an obvious geometric centre.

Prehaps this should be the default then, but I am wondering if we
couldn't also add a
parameter allowing centring via a bounding sphere:

http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Bounding_volumes_ref/Class_Min_sphere_d.html

So the syntax would be

center(sphere=true) rotate([0,30,0]) cylinder(r1=10,r2=0,h=20);

I think the minimum bounding sphere will give a centre that is the
same regardless of
rotational transformations applied.

Regards

Giles