RK
Roland Koebler
Thu, Jul 2, 2015 6:03 PM
Hi,
is there a standard way to automatically or semi-automatically center
and/or align objects?
The center-parameter of e.g. cube() can only center it in all axes or
none, but I would like to be able to selectively center it and to
align it to the positive or negative side of an axis. I know I can
do this by adding translate(), but I don't like that I have to manually
enter the size of the object into the translate-parameters.
So, I have two ideas:
-
Adding a parameter to all my modules, e.g.:
module mytest(..., align=[1,1,1]) {
...
}
"align" has three elements, one for each axis. Each element can have
three values: 0 = center on this axis, 1 = object is on positive side
of the axis, -1 = object is on the negative side of the axis.
Have you already done something like this? Is there a standard-name
for the parameter I named "align"? Or is there abetter/easier way?
-
Using/adding object-properties (or local-scoped contants):
(similar to the ideas of https://github.com/openscad/openscad/issues/301)
If I could access some object-properies (either set manually or
determined automatically like on the linked post), I could write
generic alignment-functions/modules.
Example:
module mytest() {
SIZE_X = 10; // manually given, since it could be hard to
SIZE_Y = 20; // determine automatically on more complex
SIZE_Z = 30; // objects
CENTER = [5,10,15];
color("red") // could automatically define "COLOR"
cube([10, 20, 30]);
}
module center(object, center=[false, false, false]) {
translate([center[0] ? -children().CENTER[0] : 0,
center[1] ? -children().CENTER[1] : 0,
center[2] ? -children().CENTER[2] : 0])
children();
}
module align(object, align=[0, 0, 0]) {
translate([align[0] ? -children().CENTER[0]+children().SIZE_X : 0,
align[1] ? -children().CENTER[1]+children().SIZE_Y : 0,
align[2] ? -children().CENTER[2]+children().SIZE_Z : 0])
children();
}
The code doesn't work, but the idea should be clear.
I think this approach would be quite powerful, make it possible to
automatically align or stack things, mix the colors of objects on
union()) and may things I currently don't think of. But it would
probably be quite complex, too.
What do you think?
best regards
Roland
Hi,
is there a standard way to automatically or semi-automatically center
and/or align objects?
The center-parameter of e.g. cube() can only center it in all axes or
none, but I would like to be able to selectively center it and to
align it to the positive or negative side of an axis. I know I can
do this by adding translate(), but I don't like that I have to manually
enter the size of the object into the translate-parameters.
So, I have two ideas:
1. Adding a parameter to all my modules, e.g.:
module mytest(..., align=[1,1,1]) {
...
}
"align" has three elements, one for each axis. Each element can have
three values: 0 = center on this axis, 1 = object is on positive side
of the axis, -1 = object is on the negative side of the axis.
Have you already done something like this? Is there a standard-name
for the parameter I named "align"? Or is there abetter/easier way?
2. Using/adding object-properties (or local-scoped contants):
(similar to the ideas of https://github.com/openscad/openscad/issues/301)
If I could access some object-properies (either set manually or
determined automatically like on the linked post), I could write
generic alignment-functions/modules.
Example:
module mytest() {
SIZE_X = 10; // manually given, since it could be hard to
SIZE_Y = 20; // determine automatically on more complex
SIZE_Z = 30; // objects
CENTER = [5,10,15];
color("red") // could automatically define "COLOR"
cube([10, 20, 30]);
}
module center(object, center=[false, false, false]) {
translate([center[0] ? -children().CENTER[0] : 0,
center[1] ? -children().CENTER[1] : 0,
center[2] ? -children().CENTER[2] : 0])
children();
}
module align(object, align=[0, 0, 0]) {
translate([align[0] ? -children().CENTER[0]+children().SIZE_X : 0,
align[1] ? -children().CENTER[1]+children().SIZE_Y : 0,
align[2] ? -children().CENTER[2]+children().SIZE_Z : 0])
children();
}
The code doesn't work, but the idea should be clear.
I think this approach would be quite powerful, make it possible to
automatically align or stack things, mix the colors of objects on
union()) and may things I currently don't think of. But it would
probably be quite complex, too.
What do you think?
best regards
Roland
DM
doug moen
Thu, Jul 2, 2015 7:12 PM
Solving this problem is one of my goals for the OpenSCAD2 project that I'm
working on. The code you've written for idea #2 is pretty close to valid
OpenSCAD2 code. In other words, the language does support object
properties, using pretty much the syntax you describe.
Unfortunately, this is all just in the design phase right now. There's no
working code that I can share. But I agree with your proposal.
Doug Moen.
On 2 July 2015 at 14:03, Roland Koebler rk-list@simple-is-better.org
wrote:
Hi,
is there a standard way to automatically or semi-automatically center
and/or align objects?
The center-parameter of e.g. cube() can only center it in all axes or
none, but I would like to be able to selectively center it and to
align it to the positive or negative side of an axis. I know I can
do this by adding translate(), but I don't like that I have to manually
enter the size of the object into the translate-parameters.
So, I have two ideas:
-
Adding a parameter to all my modules, e.g.:
module mytest(..., align=[1,1,1]) {
...
}
"align" has three elements, one for each axis. Each element can have
three values: 0 = center on this axis, 1 = object is on positive side
of the axis, -1 = object is on the negative side of the axis.
Have you already done something like this? Is there a standard-name
for the parameter I named "align"? Or is there abetter/easier way?
-
Using/adding object-properties (or local-scoped contants):
(similar to the ideas of
https://github.com/openscad/openscad/issues/301)
If I could access some object-properies (either set manually or
determined automatically like on the linked post), I could write
generic alignment-functions/modules.
Example:
module mytest() {
SIZE_X = 10; // manually given, since it could be hard to
SIZE_Y = 20; // determine automatically on more complex
SIZE_Z = 30; // objects
CENTER = [5,10,15];
color("red") // could automatically define "COLOR"
cube([10, 20, 30]);
}
module center(object, center=[false, false, false]) {
translate([center[0] ? -children().CENTER[0] : 0,
center[1] ? -children().CENTER[1] : 0,
center[2] ? -children().CENTER[2] : 0])
children();
}
module align(object, align=[0, 0, 0]) {
translate([align[0] ? -children().CENTER[0]+children().SIZE_X : 0,
align[1] ? -children().CENTER[1]+children().SIZE_Y : 0,
align[2] ? -children().CENTER[2]+children().SIZE_Z : 0])
children();
}
The code doesn't work, but the idea should be clear.
I think this approach would be quite powerful, make it possible to
automatically align or stack things, mix the colors of objects on
union()) and may things I currently don't think of. But it would
probably be quite complex, too.
What do you think?
best regards
Roland
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Solving this problem is one of my goals for the OpenSCAD2 project that I'm
working on. The code you've written for idea #2 is pretty close to valid
OpenSCAD2 code. In other words, the language does support object
properties, using pretty much the syntax you describe.
Unfortunately, this is all just in the design phase right now. There's no
working code that I can share. But I agree with your proposal.
Doug Moen.
On 2 July 2015 at 14:03, Roland Koebler <rk-list@simple-is-better.org>
wrote:
> Hi,
>
> is there a standard way to automatically or semi-automatically center
> and/or align objects?
>
> The center-parameter of e.g. cube() can only center it in all axes or
> none, but I would like to be able to selectively center it and to
> align it to the positive or negative side of an axis. I know I can
> do this by adding translate(), but I don't like that I have to manually
> enter the size of the object into the translate-parameters.
>
> So, I have two ideas:
>
> 1. Adding a parameter to all my modules, e.g.:
>
> module mytest(..., align=[1,1,1]) {
> ...
> }
>
> "align" has three elements, one for each axis. Each element can have
> three values: 0 = center on this axis, 1 = object is on positive side
> of the axis, -1 = object is on the negative side of the axis.
>
> Have you already done something like this? Is there a standard-name
> for the parameter I named "align"? Or is there abetter/easier way?
>
>
> 2. Using/adding object-properties (or local-scoped contants):
> (similar to the ideas of
> https://github.com/openscad/openscad/issues/301)
>
> If I could access some object-properies (either set manually or
> determined automatically like on the linked post), I could write
> generic alignment-functions/modules.
>
> Example:
>
> module mytest() {
> SIZE_X = 10; // manually given, since it could be hard to
> SIZE_Y = 20; // determine automatically on more complex
> SIZE_Z = 30; // objects
> CENTER = [5,10,15];
> color("red") // could automatically define "COLOR"
> cube([10, 20, 30]);
> }
> module center(object, center=[false, false, false]) {
> translate([center[0] ? -children().CENTER[0] : 0,
> center[1] ? -children().CENTER[1] : 0,
> center[2] ? -children().CENTER[2] : 0])
> children();
> }
> module align(object, align=[0, 0, 0]) {
> translate([align[0] ? -children().CENTER[0]+children().SIZE_X : 0,
> align[1] ? -children().CENTER[1]+children().SIZE_Y : 0,
> align[2] ? -children().CENTER[2]+children().SIZE_Z : 0])
> children();
> }
>
> The code doesn't work, but the idea should be clear.
>
> I think this approach would be quite powerful, make it possible to
> automatically align or stack things, mix the colors of objects on
> union()) and may things I currently don't think of. But it would
> probably be quite complex, too.
>
> What do you think?
>
>
> best regards
> Roland
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
>
N
Neon22
Thu, Jul 16, 2015 12:22 PM
as we need overlap sometimes to get good unions in CGAL.
how about using floats and interpreting them specially.
E.g. align=[1,1,1] does what is suggested
but align[1.1, 1.1, 1.1] would use the floating point section of teh number
to overlap at the align boundary.
The question is would [1,0,0] effectively be doing a
- translate([1,0,0]) scale([1.1, 1,1])
and therefore making the object slightly wider. So the far width was at the
exact position and the scale allowed overlap at the align boundary ?
--
View this message in context: http://forum.openscad.org/request-for-comments-object-properties-and-or-alignment-tp12983p13195.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
as we need overlap sometimes to get good unions in CGAL.
how about using floats and interpreting them specially.
E.g. align=[1,1,1] does what is suggested
but align[1.1, 1.1, 1.1] would use the floating point section of teh number
to overlap at the align boundary.
The question is would [1,0,0] effectively be doing a
- translate([1,0,0]) scale([1.1, 1,1])
and therefore making the object slightly wider. So the far width was at the
exact position and the scale allowed overlap at the align boundary ?
--
View this message in context: http://forum.openscad.org/request-for-comments-object-properties-and-or-alignment-tp12983p13195.html
Sent from the OpenSCAD mailing list archive at Nabble.com.