Nabble has removed Mailing-list integration.
Posts created here DO NOT GET SENT TO THE MAILING LIST.
Mailing-list emails DO NOT GET POSTED TO THE FORUM.
So basically the Forum is now out of date, we are looking into migrating the history.
I have code with recursive functions that use translate() to change the
current location. The code works fine, but now I have to add code that needs to know the current x, y, z location that resulted from many nested translate() functions. How can I find the current x, y, z location? Thank you! -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
jamcultur wrote
> I have code with recursive functions that use translate() to change the > current location. The code works fine, but now I have to add code that > needs > to know the current x, y, z location that resulted from many nested > translate() functions. How can I find the current x, y, z location? Your question is too vague. I think you need to post a code example and explain what you are trying to do. What is the "current location"? The (x,y,z) location of what? And what are you hoping to do with it once you find it? -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
To me, the "current location" is location that is the reference point of any
object that you draw. For example, if you wrote sphere(d=10);, the center of the sphere would be at the current location. That location could have any x, y, and z coordinates, depending on the previous translates and rotates. I need to know those coordinates in order to determine whether to draw the next object. I should also mention that there are also many rotate() functions in the recursive functions I mentioned previously. -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Administrator
|
Short answer is you can't get it from OpenSCAD.
You do all the translates etc, so you can calculate where 'here' is. There are libraries which can help like local <https://github.com/jreinhardt/local-scad> , there are others, I just can't find them ATM. ----- Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD Admin - email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. |
You mention rotate() and translate() function but I assume you mean modules. Basically you always tell OpenSCAD where something is, you can never ask it. On Sat, 2 Mar 2019 at 05:59, MichaelAtOz <[hidden email]> wrote: Short answer is you can't get it from OpenSCAD. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by jamcultur
If I correctly understand your needs: you could add absolute position
(vector) as a parameter of the recursive function, so every time you call again the function, you update the vector you pass accordingly to the applied translation. I used a similar approach to apply color to a 3D fractal, depending on the cumulative displacement from [0,0,0]. jamcultur wrote > I have code with recursive functions that use translate() to change the > current location. The code works fine, but now I have to add code that > needs > to know the current x, y, z location that resulted from many nested > translate() functions. How can I find the current x, y, z location? > Thank you! -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
You understand correctly, and I was thinking of doing exactly what you
suggest. I was hoping that OpenSCAD had an easier way to do it. OpenSCAD obviously knows the current [x, y, z] and it seems like it should be simple for it to make that information available to the program. -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
The generated geometry depends on the variables. Making the variables dependent on the geometry could create a circular dependency unless it is restricted by scope rules and would require more passes. On Sat, 2 Mar 2019 at 15:54, jamcultur <[hidden email]> wrote: You understand correctly, and I was thinking of doing exactly what you _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by jamcultur
don't know whether it will help you, but the way nophead described, is not
too difficult to go, if you have translate(), rotate(), and scale() as functions. Say your module contains code like this rotate([100,0,100]) translate([0,30,100]) rotate([33,0,100]) translate([0,0,100]) cube(100); if you want to know where cube is mapped, or where any other point q will be mapped, you just use the same transformation sequence in function syntax. q=[0,0,0]; q1 = rotate([100,0,100], translate([0,30,100], rotate([33,0,100], translate([0,0,100], q)))); echo(q1); Here is my implementation of the three functions. The code looks more difficult than it is, because the functions are part of a richer interface, accept parameter calls without [] and work recursive. They operate over points, lists of points, lists of lists of points and so on. I use them mainly in connection with sweep(), but they will also serve your needs. function translate(x=0, y=0, z=0, v) = let(v = (len(x)==3)?y:v, x = (len(x)==3)?x:[x, y, z]) len(v[0])?[for (i=v) translate(x,i)]:v+x; function rotate(x=0, y=0, z=0, v) = // 2D vectors allowed let(v = (len(x)==3)?y:v, x=(len(x)==3)?x:[x, y, z]) len(v[0])? [for(i=v) rotate(x,i)]:Rz(x[2], Ry(x[1], Rx(x[0], v))); function Rx(x, A) = len(A[0][0])?[for(i=A) Rx(x, i)]: A*[[1, 0, 0], [0, cos(x), sin(x)], [0, -sin(x), cos(x)]]; function Ry(y, A) = len(A[0][0])?[for(i=A) Ry(y, i)]: A*[[cos(y), 0, sin(y)], [0, 1, 0], [-sin(y), 0, cos(y)]]; function Rz(z, A) = len(A[0][0])? [for(i=A) Rz(z, i)]: len(A[0])==2? A*[[cos(z), sin(z)], [-sin(z), cos(z)]]: A*[[cos(z), sin(z), 0], [-sin(z), cos(z), 0], [0, 0, 1]]; function scale(x=1, y=1, z=1, v) = let(v = (len(x)==3)?y:v, x = (len(x)==3)?x:[x, y, z]) len(v[0])?[for (i=v) S_(x,i)]:[v[0]*x[0], v[1]*x[1], v[2]*x[2]]; -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by nophead
On 3/2/2019 12:17 AM, nop head wrote:
(I know that you know this.) And even then, you can only tell it where something is relative to its own transformations... you can't specify an absolute location. That is, you can't say sequence( ) of( ) transformations() { translate_back_to_origin( ) { object( ); } }
The only way to do that would be to know the sequence of transformations and unwind them.
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
I still want to know what the original poster was actually trying to do with
a specific code example. I think without that it's difficult to really say what the best solution is. Why, if you have a series of transformations, would you not just put whatever second thing you need inside that same code. What is the reason for wanting to do something later inside a series of transformations you did before? That is the obvious question I have. -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by jamcultur
On 3/2/2019 7:49 AM, jamcultur wrote:
OpenSCAD obviously knows the current [x, y, z] [ Speaking from an external observer's point of view, without
knowledge of the internals... others, feel free to correct me.] First, note that "current position" isn't the complete picture - there's also rotation, scale, and skew. I don't think it does know the current position.. It doesn't execute a program in a conventional sense, producing geometry as a direct result of the execution. Rather, it executes a program[*] that produces a tree of transformations, operations, and objects, and a subsequent step applies those transformations and operations to those objects to produce the final absolute geometry. Turn on Design/"Display CSG Tree" to see the results of the
execution. Note that the generated geometry still has each of the
transformation steps; there are no absolute coordinates.
<weeds level=deep> Even if it was a conventional language that directly generated the final geometry, I don't know if it always would know the current transformation relative to the absolute coordinate system. The most straightforward way to do it would be to have a
transformation function call its children and then apply its
transformation to them, returning a transformed object. In such a
design, each function would have no idea what coordinate system
*it* was embedded in; you would only know absolute coordinates
when you get back to the top of the call stack. </weeds> _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by adrianv
Yes indeed. I never need to do this. To put the object at the origin I simply don't put it under some transformations. If I want to transform other objects to the same place I create a module that transforms its children and apply it wherever wanted. I don't need to ask where something is because I have placed it relative to other objects in the design and then my machines make it. I sometimes add echos of sizes that hare calculated to make sure they will fit on my printers. On Sun, 3 Mar 2019 at 21:03, adrianv <[hidden email]> wrote: I still want to know what the original poster was actually trying to do with _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
This ties back to the prior threads on libraries and learning
OpenSCAD.
I think both of you have the best (and correct) strategy for approaching this. Unfortunately we don't have a lot of documentation about how to use OpenSCAD "well" so that a beginner learns to tackle things this way from the start. Whether you believe in libraries or not, coming up with resources to share this type of knowledge would be valuable. I'm not really sure how to teach it (let alone sure if I have a very good handle on many such techniques) but it'd be great to see the community discuss these types of practices so we can get them documented. On 3/3/19 3:12 PM, nop head wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by JordanBrown
JordanBrown wrote
> And even then, you can only tell it where something is relative to its > own transformations... you can't specify an absolute location. > > That is, you can't say > > sequence( ) of( ) transformations() { > translate_back_to_origin( ) { > object( ); > } > } > > The only way to do that would be to know the sequence of transformations > and unwind them. Hmm, why would one like to write this? You can simple write object( ); -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by nophead
One reason to what to know the global coordinates would be for labeling. I posted questions about this recently and got good feedback. For example, if I want to produce a printable schematic or design document for translating the on-screen object into a real-world object through traditional machining techniques, I need to know real world coordinates. So if a particular edge or point is the result of multiple transformations, it is difficult to determine that location for labeling. A great solution would be to have built-in transformation functions of vectors. But short of that, there are libraries that can do the same, so that it can be determined manually. Kevin On Sun, Mar 3, 2019 at 1:13 PM nop head <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
I should start by stating that I don’t really know what I’m talking about, so I’ve already got an excuse if my question is stupid.
As I understand it, the primary impediment of access to things like current x,y,z location and getting a list of the current points in an object is because the CGAL CSG library API that OpenSCAD is built open doesn’t provide that kind of access. On the other hand, I note that OpenJSCAD has implemented their own CSG library in javascript, which, as I understand it, does provide access to the information. Would that be the way to provide OpenSCAD with that kind of functionality? I’m certainly aware that it’s easy to wave one's hand and say “let’s just get a whole bunch of contributors who have lots of free time to create this library for absolutely no compensation”, so I’m not saying that, I’m just wondering if that would be possible path forward and if it’s ever been considered as a possible roadmap for future work. I appreciate that any CSG functionality may not be as robust as CGAL, but on the other hand there’s already situations in which I’m piecing together point lists for simple geometric constructions for polygon() and polyhedron() that get overly complex rather quickly. I was thinking that some built-in CSG for union(), difference() and intersection() might provide the functionality that many people would want, even if it collapsed under sophisticated or overly complex constructions.
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
There is no problem accessing CGAL data but I think it is only the stack of transformation matrices that would be needed and they are outside of CGAL as they are also needed for preview. And as I previously pointed out OpenSCAD evaluates all the expressions and then generates geometry. So the transformation matrices are not generated at the point you could use them in an expression. Since the user always places geometry in theory one can always work out where it is but that may require a working knowledge of trigonometry and matrix maths. On Mon, 4 Mar 2019 at 18:00, Hugo Jackson <[hidden email]> wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Thanks for the reply… I’m less ignorant than I was yesterday. :)
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In reply to this post by Parkinbot
On 3/4/2019 1:51 AM, Parkinbot wrote:
JordanBrown wroteAnd even then, you can only tell it where something is relative to its own transformations... you can't specify an absolute location. That is, you can't say sequence( ) of( ) transformations() { translate_back_to_origin( ) { object( ); } } The only way to do that would be to know the sequence of transformations and unwind them.Hmm, why would one like to write this? You can simple write object( );
It was a thought experiment, not a real-world example. The point
was that not only is it impossible to retrieve the absolute
position from inside a series of transformations, but it is also
impossible to *specify* an absolute position for whatever reason. Perhaps object() is buried in a module with other stuff that *is* intended to be relative to the transformations. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |