How to find the current x, y, z location

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

Re: How to find the current x, y, z location

On 3/4/2019 8:40 AM, Kevin Toppenberg wrote:
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.

Position isn't everything.  An object is rendered in a coordinate space that is the result of the stack of transformations that are on top of that object.  Translation is one of the transformations, but only one.  Even if you could retrieve the absolute position, if you drew text at that location it would be rotated, scaled, et cetera, and you probably wouldn't want any of that.  Even if you *could* retrieve the current origin in absolute coordinates, you couldn't do much with it - if you tried to translate( ) back to the origin, that translation would itself be subject to the stack of transformations.

    scale([5,1,1]) translate([1,1,1]) {
    	// the origin for this block is at [5,1,1]
        origin=[5,1,1];    // imagine we could get this back from OpenSCAD
        translate(-origin) text("hello");

Note that our sphere is stretched because of the scale, but is centered on [5,1,1].

Note that even though we attempted to translate the text back to the origin, we failed because -[5,1,1] times the scale of [5,1,1] is -[25,1,1], plus the "origin" is [-20,0,0].  (I don't immediately know why it ended up starting at -15.)

Note that the text is stretched in the X axis because of the scale.

Similarly, if you tried to translate back to the origin in a rotated frame of reference, you won't get what you expect.

    rotate([0,0,90]) translate([2,0,0]) {
    	// the origin for this block is at [0,2,0]
        origin=[0,2,0];    // imagine we could get this back from OpenSCAD
        translate(-origin) cube(1,center=true);

Note that the cube that was supposed to be translated back to the origin ended up nowhere near the origin, because the translate(-origin) is itself relative to a rotated coordinate system.

OpenSCAD mailing list
[hidden email]