How to track a point?

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

How to track a point?

Troberg
I have a problem where I need to place a flat object between several
supports. These supports are parametric, so size and rotation angles varies.
Also, the supports have thickness which needs to be taking into account.
(This is only the problem at hand at the moment, I have had many other more
or less similar issues in other projects, so don't dig too deep into the
details.)

Now, of course, I could do what I've done so far, and simple do a shitload
of trigonometry, but that is a total pain in the rear to maintain. I want to
work creatively, and be able to alter things as I go and as the build takes
form, and that's simply not possible when things hang on five pages of math.

So, what I'd like to do, something like adding a point object. Kind of like
a sphere, but without size and invisible. This can then be unioned,
translated, rotated and so on like any primitive. It never changes size, of
course, so scale operations and so on only move it if it's unioned with
other stuff.

Then, at a later point, I want to be able to get the current coordinations
of this point. That way, I could define the "attachment point", union it to
whatever part it belongs to, move and rotate the part, then ask the
"attachment point" what coordinate it has now, and use that for placement of
other stuff.

Now, this is how I would prefer to do it, but that doesn't seem possible at
the moment. So, are there any alternative solutions that work?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

NateTG
Currently there's no way to get geometry information (like coordinates) back
into the code once it's gone to the geometry engine.  (There have been
various proposals to change that none has come to fruition so far.)

Something that might work is to generate transformation matrices that
correspond to your movements, and then apply them to a vector that
represents the starting position of your test point, but even making that
work will probably require heavy restructuring of your program or introduce
more code maintenance problems than it solves.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

thehans
In reply to this post by Troberg
Hi Troberg,

This reminds me a little bit of a concept I was playing with a few
months back, but hadn't gotten around to sharing yet.  Its not a
direct solution to what you are asking but I think the concept might
be applicable in a similar way for what you want.

In this case I wanted to create some continuous pipe using simple
operations and not have to think too hard about where the endpoint is
after a bunch of turns etc.

I just cleaned up my code and added some comments for better
user-friendliness.
In the example below, I guess I am considering the final sphere() call
to be analogous to your concept of a point object.

```
// Pipe library demonstrating a concept of chained operations

$fn = 72; // define exact number of fragments in curves
// using $fs instead would cause some mismatched # of edges during tapers
echo(str("For best results, all angles should be multiples of ",
360/$fn, " degrees"));

// Example of how to use pipe
// Note that all calls are chained (there's only one semicolon, at the end)
// children are automatically transformed to the end of the "path"
pipe([4,6])
  elbow()
  straight(10)
  taper_to([8,10], length=10)
  elbow(angle=180, heading=30)
  straight(20)
  sphere(d=6); // we can even terminate the chain with a module that
doesn't "know" anything about our pipes


// initializes the pipe size, but draws nothing
module pipe(size=[2,4]) {
  $pipe_size = size;
  children();
}

module straight(length=10) {
  linear_extrude(height=length) difference() {
    circle(d=$pipe_size[1]);
    circle(d=$pipe_size[0]);
  }
  translate([0,0,length]) children();
}

// no-operation
// This aids in passing data via special variables from parent to children
// Related issue: https://github.com/openscad/openscad/issues/2104
module noop() children();
// calls to noop() could also be replaced by let() (experimental), if
running a development snapshot.

module taper_to(size, length=10) {
  IR1 = $pipe_size[0]/2;
  OR1 = $pipe_size[1]/2;
  IR2 = size[0]/2;
  OR2 = size[1]/2;
  points = [
    [IR1, 0], [OR1, 0],
    [OR2, length], [IR2, length]
  ];

  rotate_extrude() polygon(points);

  translate([0,0,length])
    noop($pipe_size=size)
      children();
}

// R = center radius of elbow
// angle = the angle through which the elbow bends.
// heading = which direction it bend towards
module elbow(R=$pipe_size[1]/2, angle=90, heading=0) {
  OR = $pipe_size[1]/2;

  if (angle != 0) {
    rotate(heading) translate([R+OR,0]) rotate([-90,0,0]) {
      rotate_extrude(angle=angle)
      translate([-R-OR,0]) difference() {
        circle(d=$pipe_size[1]);
        circle(d=$pipe_size[0]);
      }
    }
  }
  rotate(heading) translate([R+OR,0,0]) rotate([0,angle,0])
translate([-R-OR,0,0]) children();
}
```

What do you think?  Is that helpful at all for what you need to do?

-Hans

On Mon, Feb 5, 2018 at 2:35 AM, Troberg <[hidden email]> wrote:

> I have a problem where I need to place a flat object between several
> supports. These supports are parametric, so size and rotation angles varies.
> Also, the supports have thickness which needs to be taking into account.
> (This is only the problem at hand at the moment, I have had many other more
> or less similar issues in other projects, so don't dig too deep into the
> details.)
>
> Now, of course, I could do what I've done so far, and simple do a shitload
> of trigonometry, but that is a total pain in the rear to maintain. I want to
> work creatively, and be able to alter things as I go and as the build takes
> form, and that's simply not possible when things hang on five pages of math.
>
> So, what I'd like to do, something like adding a point object. Kind of like
> a sphere, but without size and invisible. This can then be unioned,
> translated, rotated and so on like any primitive. It never changes size, of
> course, so scale operations and so on only move it if it's unioned with
> other stuff.
>
> Then, at a later point, I want to be able to get the current coordinations
> of this point. That way, I could define the "attachment point", union it to
> whatever part it belongs to, move and rotate the part, then ask the
> "attachment point" what coordinate it has now, and use that for placement of
> other stuff.
>
> Now, this is how I would prefer to do it, but that doesn't seem possible at
> the moment. So, are there any alternative solutions that work?
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

Troberg
> This reminds me a little bit of a concept I was playing with a few
months back, but hadn't gotten around to sharing yet.  Its not a
direct solution to what you are asking but I think the concept might
be applicable in a similar way for what you want.

A really neat solution, but I think it's hard to adapt to my case.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

Troberg
In reply to this post by NateTG
> Currently there's no way to get geometry information (like coordinates)
back
into the code once it's gone to the geometry engine.  (There have been
various proposals to change that none has come to fruition so far.)

I suspected as much. As much as I love OpenSCAD, its "fire and forget"
design can be very frustrating at times, especially when things get
complicated, and especially if you, like me, come from a traditional object
oriented programming background. To be able to keep some object reference
and use it to access properties of the object would make the code so much
simpler, and not just in complex cases, but also in simpler cases (such as
when a construction stacks elements, and you wouldn't have to reference
everything as a sum of heights from the ground all the time).



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

cacb
On 2018-02-06 10:30, Troberg wrote:

> I suspected as much. As much as I love OpenSCAD, its "fire and forget"
> design can be very frustrating at times, especially when things get
> complicated, and especially if you, like me, come from a traditional
> object
> oriented programming background. To be able to keep some object
> reference
> and use it to access properties of the object would make the code so
> much
> simpler, and not just in complex cases, but also in simpler cases (such
> as
> when a construction stacks elements, and you wouldn't have to reference
> everything as a sum of heights from the ground all the time).

I have a similar background...
Here's a tiny example of transforming a point with AngelScript, and
using the result:

    pos3d@ p = rotate_z(deg:30)*translate(50,0,0)*pos3d(1,0,0);
    solid@ s = translate(p.x(),p.y(),p.z())*cube(size:25,center:true);

p becomes (44.1673, 25.5, 0) in this case.

This issue represents a major difference between a declarative language
like OpenSCAD compared to procedural/OO languages.

Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: How to track a point?

Troberg
Well, not even transforming the point is straightforward, as the points are
not on the ends of the supports, the supports does not hinge on the axis the
points are on, and the supports have thickness.

Think of a T, hinged a bit down at the vertical column. The T has thickness,
and it can hinge in two directions. The points are various points on the
surface of the T.

Sure, it's very much doable, but it soon gets very messy, especially when I
want to change dimensions and angles around to get it right.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org