New features request: extractpolyhedron & extractmatrix

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

New features request: extractpolyhedron & extractmatrix

Henry Baker
It might be nice to be able to extract a polyhedron from a CSG object for additional processing.

Here's the idea:

newpolyhedron=extractpolyhedron(cube(10));

// newpolyhedron is a pair: [points,triangles] such that

polyhedron(points=newpolyhedron[0],triangles=newpolyhedron[1]);

// will reproduce the cube.

---
Also,

newmatrix=extractmatrix(translate([10,0,20]) rotate([0,45,0]));

would produce a matrix suitable for use in 'multmatrix'.
---
Alternatively, (& perhaps better) it would be nice to apply 'translate' and 'rotate' sequences to a list of points:

newpoints=translate([10,0,20]) rotate([0,45,0]) [point0,point1,point2,...];

It is then possible to extract the matrix with the following data:

newpoints=translate([10,0,20]) rotate([0,45,0]) [[0,0,0],[1,0,0],[0,1,0],[0,0,1]];

_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

kintel
Administrator
On 2013-06-29, at 12:49 , Henry Baker wrote:

> It might be nice to be able to extract a polyhedron from a CSG object for additional processing.
> newmatrix=extractmatrix(translate([10,0,20]) rotate([0,45,0]));
>
I've been thinking about this - basically, the general idea is to be able to store objects and matrices in variables and reference them later.
They could even be sent as parameters to custom modules, as an alternative to using the current child() concept.

Look at e.g. CoffeeSCAD for ideas how to do geometry with a real programming language, as that's the direction such discussions are leading.
One day, this might be the direction OpenSCAD is going (and perhaps letting today's OpenSCAD language be a Domain Specific Language on top of this). Anyway, we need more developer resources to seriously move forward with these things..

 -Marius

_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

nophead
It is hard for me to understand why this is necessary Henry. Please can you explain the use cases.

Why do you want to store a transformation and then pass it to multmatrix? Why not simply create a module that does the translate and rotate and use that instead where you would have multmatrix(newmatrix)?

Why do you want to compute the scaled and rotated points of a cube? What do you do with them next?




On 29 June 2013 19:54, Marius Kintel <[hidden email]> wrote:
On 2013-06-29, at 12:49 , Henry Baker wrote:

> It might be nice to be able to extract a polyhedron from a CSG object for additional processing.
> newmatrix=extractmatrix(translate([10,0,20]) rotate([0,45,0]));
>
I've been thinking about this - basically, the general idea is to be able to store objects and matrices in variables and reference them later.
They could even be sent as parameters to custom modules, as an alternative to using the current child() concept.

Look at e.g. CoffeeSCAD for ideas how to do geometry with a real programming language, as that's the direction such discussions are leading.
One day, this might be the direction OpenSCAD is going (and perhaps letting today's OpenSCAD language be a Domain Specific Language on top of this). Anyway, we need more developer resources to seriously move forward with these things..

 -Marius

_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

Henry Baker
I'm not that interested in cubes, per se.  I was simply using a cube as an example.

I'm building a large polyhedron out of points & triangles.

I'd like to transform some of the points for this polyhedron using one matrix, and other of the points using a different matrix.

Applying a transformation to the entire polyhedron isn't what I need.

Putting off the transformation until the entire structure is built isn't an option.

Yes, I can build my own transformation matrices, but it's painful and I end up not being able to use all of the transformation machinery that OpenSCAD has already developed.

It should be possible to describe to OpenSCAD a sequence of transformations -- e.g., translate, rotate, multmatrix, etc. -- and construct a single transformation matrix that I can use on sets of points.

At 12:04 PM 6/29/2013, nop head wrote:
>Why do you want to compute the scaled and rotated points of a cube? What do you do with them next?



_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

nophead
The issue is translate(), rotate() etc work on a tree of geometry, not matrix expressions. There is currently no way to put geometry into expressions. 

I think you can write functions called translate(), rotate(), etc that return matrices and then multiply the results together to make the combined transformation to pass to multmatrix. Would that do what you want?



On 30 June 2013 15:49, Henry Baker <[hidden email]> wrote:
I'm not that interested in cubes, per se.  I was simply using a cube as an example.

I'm building a large polyhedron out of points & triangles.

I'd like to transform some of the points for this polyhedron using one matrix, and other of the points using a different matrix.

Applying a transformation to the entire polyhedron isn't what I need.

Putting off the transformation until the entire structure is built isn't an option.

Yes, I can build my own transformation matrices, but it's painful and I end up not being able to use all of the transformation machinery that OpenSCAD has already developed.

It should be possible to describe to OpenSCAD a sequence of transformations -- e.g., translate, rotate, multmatrix, etc. -- and construct a single transformation matrix that I can use on sets of points.

At 12:04 PM 6/29/2013, nop head wrote:
>Why do you want to compute the scaled and rotated points of a cube? What do you do with them next?



_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

Henry Baker
Yes, I've done that, but it seems silly to constantly reinvent the wheel...

The need to do duplicate all of this machinery points out a problem in the design of the language.

At 12:56 PM 6/30/2013, nop head wrote:
>I think you can write functions called translate(), rotate(), etc that return matrices and then multiply the results together to make the combined transformation to pass to multmatrix. Would that do what you want?


_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

nophead
It only needs to be done once and put in a library. Better than inventing new syntax and complicating the language in my opinion.


On 30 June 2013 21:47, Henry Baker <[hidden email]> wrote:
Yes, I've done that, but it seems silly to constantly reinvent the wheel...

The need to do duplicate all of this machinery points out a problem in the design of the language.

At 12:56 PM 6/30/2013, nop head wrote:
>I think you can write functions called translate(), rotate(), etc that return matrices and then multiply the results together to make the combined transformation to pass to multmatrix. Would that do what you want?


_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

Henry Baker
Well, if you're going to do that, then you can simplify the language substantially by getting rid of scale, resize, rotate, translate, mirror, etc., in favor of your library + just multmatrix:

multmatrix(m=translate([0,1,0])*rotate([60,0,0]))
cube(10);

At 02:07 PM 6/30/2013, nop head wrote:
>It only needs to be done once and put in a library. Better than inventing new syntax and complicating the language in my opinion.


_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

nophead
Yes but it is ugly for the common usage case, which is making objects by operation on solids, not building them from points.


On 30 June 2013 22:37, Henry Baker <[hidden email]> wrote:
Well, if you're going to do that, then you can simplify the language substantially by getting rid of scale, resize, rotate, translate, mirror, etc., in favor of your library + just multmatrix:

multmatrix(m=translate([0,1,0])*rotate([60,0,0]))
cube(10);

At 02:07 PM 6/30/2013, nop head wrote:
>It only needs to be done once and put in a library. Better than inventing new syntax and complicating the language in my opinion.


_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

kintel
Administrator
In reply to this post by Henry Baker
On 2013-06-30, at 17:37 , Henry Baker wrote:

> Well, if you're going to do that, then you can simplify the language substantially by getting rid of scale, resize, rotate, translate, mirror, etc.

I think it would be possible to get rid of a lot more by redesigning the language / core library to supply only some core, orthogonal operators/modules, and define the rest in a built-in library. Something to think about for OpenSCAD language definition V2.

As I mentioned, one of my lines of thinking, longer term (depending on resources), is to define a clean DSL (Domain Specific Language) on top of a more general language, and make it technically possible to write modules in the general language in order to provide DSL constructs/modules, but make the general language interpretable, not C++ to make it possible to implement such modules in user-space.

 -Marius

_______________________________________________
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: New features request: extractpolyhedron & extractmatrix

Henry Baker
In reply to this post by nophead
That's a perfect argument for 'macros': where the underlying language is already sufficiently powerful, but you want to 'prettify' certain common constructs.

I.e., make rotation, translate, etc., 'macros' which all expand into a call upon 'multmatrix' and the library functions for constructing rotation matrices, translation matrices, etc.

At 02:44 PM 6/30/2013, nop head wrote:

>Yes but it is ugly for the common usage case, which is making objects by operation on solids, not building them from points.
>
>On 30 June 2013 22:37, Henry Baker <[hidden email]> wrote:
>Well, if you're going to do that, then you can simplify the language substantially by getting rid of scale, resize, rotate, translate, mirror, etc., in favor of your library + just multmatrix:
>
>multmatrix(m=translate([0,1,0])*rotate([60,0,0]))
>cube(10);
>
>At 02:07 PM 6/30/2013, nop head wrote:
>>It only needs to be done once and put in a library. Better than inventing new syntax and complicating the language in my opinion.

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