Discussion:
[OpenSCAD] Is it possible to obtain the current transformation?
Eric Hazen
2013-03-22 19:30:04 UTC
Permalink
Hello Everyone-

I'm wondering if it is possible from within a script to access the
transformation
and rotation which are currently in effect?

For example, if there were a function "GetCurrentTransformMatrix()" one
could do:

m = GetCurrentTransformMatrix();

tx = m[0][3];
ty = m[1][3];
tz = m[2][3];

The use case is to extract coordinates of a few key points in a complex
model using
the "echo" command.

The reason this isn't trivial is because I have a hierarchy of
sub-assemblies which
all have different translations/rotations, so it is somewhat troublesome to
figure out the final XYZ of points within the sub-assemblies.

Thanks much for any ideas!

-Eric
lobrien
2018-09-24 21:08:25 UTC
Permalink
bump

It would help when refactoring complex objects.



--
Sent from: http://forum.openscad.org/
Hans L
2018-09-25 03:31:04 UTC
Permalink
It don't think it really makes sense with the way that OpenSCAD works
to need or even be able to use this information. If you assigned the
current transformation in some code block to a variable, that variable
is scoped to that block, so what are you going to do with it that you
couldn't do by just inserting some geometry directly into that block
to give it the same transformation?

Also keep in mind you can always add a call to children(); from within
a user-defined module to apply some transformation to "TBD"
later-inserted geometries.

Here is a basic example:

```
$fs = 0.5;
$fa = 0.2;
pole_d = 2;
pole_h = 100;

module pole(d,h) {
cylinder(d=d,h=h);

translate([0,0,h]) // put children at top
children();
}

module flagpole_tip(d) {
sphere(d=d);
}


// pole module can automatically position children
pole(pole_d, pole_h) {
flagpole_tip(pole_d*2);
}

// translate the pole along X and children follow
translate([0,50,0]) pole(pole_d, pole_h)
flagpole_tip(pole_d*2);

```

lobrien, Do you have an example of a script where you think having
this data would help? There's probably an alternate way of looking at
it that doesn't require "knowing" the transformation like that.
Post by lobrien
bump
It would help when refactoring complex objects.
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Loading...