Local coordinate systems

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

Local coordinate systems

Johannes Reinhardt
Hi,

I am looking for ways to make it easier to use parts from BOLTS
(http://jreinhardt.github.io/BOLTS/index.html) in OpenSCAD. At the
moment it is a bit awkward because one has to know precisely how the
BOLTS part is positioned and oriented  and then has to translate and
rotate it around. This often requires the knowledge of some dimensions
of the part, so one has to query BOLTS about it, and suddenly it is a
lot of code that is difficult to read and annoying to write.

I believe that scope is a fundamental ingredient to clarity and brevity
in programming. Allowing the programmer to think only about the current
problem he is attacking, while moving everything else out of sight,
results in clean and readable code.

While I was playing obijuans attach library
(https://github.com/Obijuan/obiscad, or
http://www.thingiverse.com/thing:30136), I realised, that his
connectors are basically local coordinate systems.

I like the idea of local coordinate systems, because it is a local
scope that can be convenient to think in. It also seems a promising
approach to avoid or at least reduce the cumbersome and
difficult nested transformations or complicated arguments that I often
end up with. Think translate([h-2*l,40-k,a+b+f-c]).

I hacked together a bit of code to do that. At the moment it allows to
do three things:

* Create and display coordinate systems (lists of lists with origin and
  x,y,z axes, but the user doesn't need to know)
* move and rotate a object (or a whole tree) from the global coordinate
  system into a local one.
* move and align a coordinate system and a object (or a tree) with
  another coordinate system

The first and the last operation are slightly improved variations of
the functionality of the attach library.

For BOLTS it could be very nice to use the align operation to position
a certain point of a part at specific location ("put that bolt the so
that its tip is here" or "the head of that bolt should touch this
face"). I will explore this possibility.

But I am sure that this code could be useful in other respects,
therefore I put it on GitHub:

https://github.com/jreinhardt/local-scad

You can download a zip archive with the scad files here:

https://github.com/jreinhardt/local-scad/archive/master.zip

I am happy to hear about any ideas for extensions, applications or
improvements.

Greetings

Johannes






--

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Local coordinate systems

szabi
Nice!

I found myself often translate-rotate-translating stuff, often involving higher math.
This could really help!

Thanks!

Szelp, André Szabolcs

+43 (650) 79 22 400


On Thu, Dec 5, 2013 at 9:47 PM, Johannes Reinhardt <[hidden email]> wrote:
Hi,

I am looking for ways to make it easier to use parts from BOLTS
(http://jreinhardt.github.io/BOLTS/index.html) in OpenSCAD. At the
moment it is a bit awkward because one has to know precisely how the
BOLTS part is positioned and oriented  and then has to translate and
rotate it around. This often requires the knowledge of some dimensions
of the part, so one has to query BOLTS about it, and suddenly it is a
lot of code that is difficult to read and annoying to write.

I believe that scope is a fundamental ingredient to clarity and brevity
in programming. Allowing the programmer to think only about the current
problem he is attacking, while moving everything else out of sight,
results in clean and readable code.

While I was playing obijuans attach library
(https://github.com/Obijuan/obiscad, or
http://www.thingiverse.com/thing:30136), I realised, that his
connectors are basically local coordinate systems.

I like the idea of local coordinate systems, because it is a local
scope that can be convenient to think in. It also seems a promising
approach to avoid or at least reduce the cumbersome and
difficult nested transformations or complicated arguments that I often
end up with. Think translate([h-2*l,40-k,a+b+f-c]).

I hacked together a bit of code to do that. At the moment it allows to
do three things:

* Create and display coordinate systems (lists of lists with origin and
  x,y,z axes, but the user doesn't need to know)
* move and rotate a object (or a whole tree) from the global coordinate
  system into a local one.
* move and align a coordinate system and a object (or a tree) with
  another coordinate system

The first and the last operation are slightly improved variations of
the functionality of the attach library.

For BOLTS it could be very nice to use the align operation to position
a certain point of a part at specific location ("put that bolt the so
that its tip is here" or "the head of that bolt should touch this
face"). I will explore this possibility.

But I am sure that this code could be useful in other respects,
therefore I put it on GitHub:

https://github.com/jreinhardt/local-scad

You can download a zip archive with the scad files here:

https://github.com/jreinhardt/local-scad/archive/master.zip

I am happy to hear about any ideas for extensions, applications or
improvements.

Greetings

Johannes






--

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: Local coordinate systems

Johannes Reinhardt
In reply to this post by Johannes Reinhardt
Hi,

as a follow up to my last message I wanted to report on the progress of
using the local coordinate system/connector approach for positioning
parts from BOLTS (http://jreinhardt.github.io/BOLTS/index.html).

I integrated local.scad (https://github.com/jreinhardt/local-scad) into
BOLTS. A part can now also provide a number of connectors, that allow
convenient positioning. This results in very compact code. For example
a bolted connection can be written like this:

include <BOLTS.scad>

cube([10,40,50]);

//connectors
cube_cs = new_cs(origin = [10,20,20], axes = [[-1,0,0],[0,-1,0]]);
washer_cs = ISO7089_conn("top","M4");
bolt_cs = ISO4017_conn("root","M4",20);
nut_cs = ISO4035_conn("bottom","M4");

//connectors can be displayed with
//show_cs(cube_cs);

//thickness of washer
s = get_dim(ISO7089_dims("M4"),"s");

//position washer and bolt at the location specified by cube_cs
align(washer_cs,cube_cs) ISO7089("M4");
align(bolt_cs,cube_cs,[-s,0,0]) ISO4017("M4",20);
align(washer_cs,cube_cs,[10+s,0,0]) ISO7089("M4");
align(nut_cs,cube_cs,[10+s,0,0]) ISO4035("M4");


which is readable, compact and flexible. To change the position or
orientation of the bolted connection, one just has to change cube_cs.
Changing the size of the bolts and washers change M4 is also easy.

You can try this functionality with the most recent development snapshot
from the BOLTS page
http://jreinhardt.github.io/BOLTS/downloads.html

Not all parts have connectors yet, but nuts, washers, hex bolts and
batteries do. The names of the connectors are listed on the part page
in the OpenSCAD section:
http://jreinhardt.github.io/BOLTS/html/index.html

I am asking you for feedback about this. In particular the syntax is not
yet set in stone. At the moment a connector is selected by calling a
function with a name, while dimensions are returned all together as a
pseudo-hash (list of lists with names and values, see
http://jreinhardt.github.io/BOLTS/doc/openscad/usage.html) and can be
queried later. I am not yet sure which way I prefer, but probably it is
a good idea to have it consistent.

One could also integrate the align functionality into the part modules,
so that one could write something like

ISO7089("M4",align=cube_cs,anchor="top");
ISO4017("M4",20,align=cube_cs,anchor="root",displace=[-s,0,0]);
...

which is somehow nicer and more compact, but puts some restrictions on
part parameter names.

I am looking forward to hear about your opinions and ideas

Greetings

Johannes



On Thu, 5 Dec 2013 21:47:52 +0100
Johannes Reinhardt <[hidden email]> wrote:

> Hi,
>
> I am looking for ways to make it easier to use parts from BOLTS
> (http://jreinhardt.github.io/BOLTS/index.html) in OpenSCAD. At the
> moment it is a bit awkward because one has to know precisely how the
> BOLTS part is positioned and oriented  and then has to translate and
> rotate it around. This often requires the knowledge of some dimensions
> of the part, so one has to query BOLTS about it, and suddenly it is a
> lot of code that is difficult to read and annoying to write.
>
> I believe that scope is a fundamental ingredient to clarity and
> brevity in programming. Allowing the programmer to think only about
> the current problem he is attacking, while moving everything else out
> of sight, results in clean and readable code.
>
> While I was playing obijuans attach library
> (https://github.com/Obijuan/obiscad, or
> http://www.thingiverse.com/thing:30136), I realised, that his
> connectors are basically local coordinate systems.
>
> I like the idea of local coordinate systems, because it is a local
> scope that can be convenient to think in. It also seems a promising
> approach to avoid or at least reduce the cumbersome and
> difficult nested transformations or complicated arguments that I often
> end up with. Think translate([h-2*l,40-k,a+b+f-c]).
>
> I hacked together a bit of code to do that. At the moment it allows to
> do three things:
>
> * Create and display coordinate systems (lists of lists with origin
> and x,y,z axes, but the user doesn't need to know)
> * move and rotate a object (or a whole tree) from the global
> coordinate system into a local one.
> * move and align a coordinate system and a object (or a tree) with
>   another coordinate system
>
> The first and the last operation are slightly improved variations of
> the functionality of the attach library.
>
> For BOLTS it could be very nice to use the align operation to position
> a certain point of a part at specific location ("put that bolt the so
> that its tip is here" or "the head of that bolt should touch this
> face"). I will explore this possibility.
>
> But I am sure that this code could be useful in other respects,
> therefore I put it on GitHub:
>
> https://github.com/jreinhardt/local-scad
>
> You can download a zip archive with the scad files here:
>
> https://github.com/jreinhardt/local-scad/archive/master.zip
>
> I am happy to hear about any ideas for extensions, applications or
> improvements.
>
> Greetings
>
> Johannes
>
>
>
>
>
>



--

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566