discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

flattening curved surfaces

R
runsun
Tue, Dec 27, 2016 5:31 PM

@nophead: brilliant solution.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19780.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

@nophead: brilliant solution. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19780.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Dec 27, 2016 5:42 PM

Thanks.

The union with nothing is of course redundant (part of some debug code I
forgot to remove) and intersection(c) should be just intersection().

On 27 December 2016 at 17:31, runsun runsun@gmail.com wrote:

@nophead: brilliant solution.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ),
runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ),
matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif ,
prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon ,
chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB
, CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp ,
blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/
flattening-curved-surfaces-tp19727p19780.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Thanks. The union with nothing is of course redundant (part of some debug code I forgot to remove) and intersection(c) should be just intersection(). On 27 December 2016 at 17:31, runsun <runsun@gmail.com> wrote: > @nophead: brilliant solution. > > > > ----- > > $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), > runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: Bezier , hash ( 2 ), > matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , > prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , > chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB > , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , > blockscad , openjscad , on AWS ( pdf ), support_tools > > -- > View this message in context: http://forum.openscad.org/ > flattening-curved-surfaces-tp19727p19780.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
R
runsun
Tue, Dec 27, 2016 6:35 PM

Here is my polyhedron solution.

  1. Shape made with polyhedron
  2. Angles and len of edges are copied from the shape to a flat surface one
    by one through a recursive function:

http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface.png

In progress:

http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface_2.png

  1. Final (with increased resolution):

http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface_3.png

Conceptually it's easy to understand, and no need to worry about the
triangulation/edge-finding, etc. But:

a) As pointed out by Parkinbot on nophead's approach, this approach bears
the same condition that the shape needs to be known, and each shape has to
be handled separately.

b) In addition, it requires somewhat extensive user functions to calculate
and copy/move the angles and edges, which is not an easy task in OpenSCAD.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19782.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Here is my polyhedron solution. 1) Shape made with polyhedron 2) Angles and len of edges are copied from the shape to a flat surface one by one through a recursive function: <http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface.png> In progress: <http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface_2.png> 3) Final (with increased resolution): <http://forum.openscad.org/file/n19782/161227_runsun_flatten_surface_3.png> Conceptually it's easy to understand, and no need to worry about the triangulation/edge-finding, etc. But: a) As pointed out by Parkinbot on nophead's approach, this approach bears the same condition that the shape needs to be known, and each shape has to be handled separately. b) In addition, it requires somewhat extensive user functions to calculate and copy/move the angles and edges, which is not an easy task in OpenSCAD. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19782.html Sent from the OpenSCAD mailing list archive at Nabble.com.
WW
William W Martin
Tue, Dec 27, 2016 6:43 PM

Hi,

I'm not a math guy, but came across this info and was curious if any
"real math" folks on this list have considered using gpu accelerated
code for some of the slow parts of OPENscad. Not a universal solution,
of course, but I suspect the majority of folks using OPENscad for
anything serious have some sort of decent graphics card in their
computer. Maybe a compile-time option to switch on accelerated functions?

see: https://developer.nvidia.com/gpu-accelerated-libraries for an idea
of what is out there already tuned up for gpu hardware...

Bill M

On 12/26/2016 05:28 AM, Parkinbot wrote:

It is always a good project to brush up your math.

dot product

This is the scalar product to be used for the threshold criterium. Apply it
with the normalized (i.e. length=1) normals of your triangles.

cross product

being applied to two vectors spanned by your triag's vertices will get you
the normal of your triangle. Adapt orientation by inverting the sign. Divide
this vector by its length and you get a normalized normal. If you start from
an STL you will already find this value for each triangle there.

angle between two vectors

the scalarproduct of two normalized vectors will be cos(angle). So
acos(dot(a,b)) is your friend.

rotate points around an axis

you find the three matrices in wikipedia

  1. a complete library for these kinds of routines ... written in ...
    Pascal.  Yeah.  I know.  Old habits die hard.
Hi, I'm not a math guy, but came across this info and was curious if any "real math" folks on this list have considered using gpu accelerated code for some of the slow parts of OPENscad. Not a universal solution, of course, but I suspect the majority of folks using OPENscad for anything serious have some sort of decent graphics card in their computer. Maybe a compile-time option to switch on accelerated functions? see: https://developer.nvidia.com/gpu-accelerated-libraries for an idea of what is out there already tuned up for gpu hardware... Bill M On 12/26/2016 05:28 AM, Parkinbot wrote: > It is always a good project to brush up your math. > >> dot product > This is the scalar product to be used for the threshold criterium. Apply it > with the normalized (i.e. length=1) normals of your triangles. > > >> cross product > being applied to two vectors spanned by your triag's vertices will get you > the normal of your triangle. Adapt orientation by inverting the sign. Divide > this vector by its length and you get a normalized normal. If you start from > an STL you will already find this value for each triangle there. > > >> angle between two vectors > the scalarproduct of two normalized vectors will be cos(angle). So > acos(dot(a,b)) is your friend. > > >> rotate points around an axis > you find the three matrices in wikipedia > > >> 1) a complete library for these kinds of routines ... written in ... >> Pascal. Yeah. I know. Old habits die hard. > http://www.dtic.mil/dtic/tr/fulltext/u2/a218917.pdf > > > > > > -- > View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19760.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
N
nophead
Tue, Dec 27, 2016 6:46 PM

How did you work out the original polyhedron? Did you calculate the
intersection of cylinders mathematically?

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19784.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

How did you work out the original polyhedron? Did you calculate the intersection of cylinders mathematically? -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19784.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Tue, Dec 27, 2016 8:02 PM

nophead wrote

How did you work out the original polyhedron? Did you calculate the
intersection of cylinders mathematically?

It was done by making 3 arcs, one on the xy-plane (red line below), two on
the yz-plane (green and blue lines), then merge them (for each point, taking
x,y from the red, and z from the green or blue):

http://forum.openscad.org/file/n19786/161227_runsun_flatten_surface_4.png

The position of the centers as well as the radius of those arcs are manually
chosen to make the outcome match the shape presented by jon_bondy.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19786.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

nophead wrote > How did you work out the original polyhedron? Did you calculate the > intersection of cylinders mathematically? It was done by making 3 arcs, one on the xy-plane (red line below), two on the yz-plane (green and blue lines), then merge them (for each point, taking x,y from the red, and z from the green or blue): <http://forum.openscad.org/file/n19786/161227_runsun_flatten_surface_4.png> The position of the centers as well as the radius of those arcs are manually chosen to make the outcome match the shape presented by jon_bondy. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19786.html Sent from the OpenSCAD mailing list archive at Nabble.com.
RP
Ronaldo Persiano
Tue, Dec 27, 2016 8:51 PM

runsun,

You say you don't have to worry about the triangulation but your code
implicitly knows the triangulation. In a more general case, you will need
to traverse it.

2016-12-27 16:46 GMT-02:00 nophead nop.head@gmail.com:

How did you work out the original polyhedron? Did you calculate the
intersection of cylinders mathematically?

--
View this message in context: http://forum.openscad.org/
flattening-curved-surfaces-tp19727p19784.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

runsun, You say you don't have to worry about the triangulation but your code implicitly *knows* the triangulation. In a more general case, you will need to traverse it. 2016-12-27 16:46 GMT-02:00 nophead <nop.head@gmail.com>: > How did you work out the original polyhedron? Did you calculate the > intersection of cylinders mathematically? > > > > -- > View this message in context: http://forum.openscad.org/ > flattening-curved-surfaces-tp19727p19784.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
R
runsun
Tue, Dec 27, 2016 10:02 PM

Ronaldo wrote

You say you don't have to worry about the triangulation but your code
implicitly knows the triangulation. In a more general case, you will
need
to traverse it.

I only know that I coded without thinking anything about the triangulation,
which, is still a pretty new concept to me. It's likely that I have been
doing triangulation-related stuff but not aware it's called triangulation.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19793.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ronaldo wrote > You say you don't have to worry about the triangulation but your code > implicitly *knows* the triangulation. In a more general case, you will > need > to traverse it. I only know that I coded without thinking anything about the triangulation, which, is still a pretty new concept to me. It's likely that I have been doing triangulation-related stuff but not aware it's called triangulation. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: Bezier , hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ), support_tools -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19793.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Dec 27, 2016 10:49 PM

I see, I didn't realise it was that simple. I think it is a special case
because the cylinders are orthogonal and aligned with the axes.

On 27 December 2016 at 20:02, runsun runsun@gmail.com wrote:

nophead wrote

How did you work out the original polyhedron? Did you calculate the
intersection of cylinders mathematically?

It was done by making 3 arcs, one on the xy-plane (red line below), two on
the yz-plane (green and blue lines), then merge them (for each point,
taking
x,y from the red, and z from the green or blue):

<http://forum.openscad.org/file/n19786/161227_runsun_flatten_surface_4.png

The position of the centers as well as the radius of those arcs are
manually
chosen to make the outcome match the shape presented by jon_bondy.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ),
runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: Bezier , hash ( 2 ),
matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif ,
prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon ,
chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB
, CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp ,
blockscad , openjscad , on AWS ( pdf ), support_tools

--
View this message in context: http://forum.openscad.org/
flattening-curved-surfaces-tp19727p19786.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I see, I didn't realise it was that simple. I think it is a special case because the cylinders are orthogonal and aligned with the axes. On 27 December 2016 at 20:02, runsun <runsun@gmail.com> wrote: > nophead wrote > > How did you work out the original polyhedron? Did you calculate the > > intersection of cylinders mathematically? > > It was done by making 3 arcs, one on the xy-plane (red line below), two on > the yz-plane (green and blue lines), then merge them (for each point, > taking > x,y from the red, and z from the green or blue): > > <http://forum.openscad.org/file/n19786/161227_runsun_flatten_surface_4.png > > > > The position of the centers as well as the radius of those arcs are > manually > chosen to make the outcome match the shape presented by jon_bondy. > > > > ----- > > $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), > runscad.py ( 2 , git ), synwrite ( 2 ); &nbsp; $ tips: Bezier , hash ( 2 ), > matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , > prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , > chfont , tailRecur ( 2 , 3 , 4 ), isosphere ( 2 ), area , vol/center , RGB > , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , > blockscad , openjscad , on AWS ( pdf ), support_tools > > -- > View this message in context: http://forum.openscad.org/ > flattening-curved-surfaces-tp19727p19786.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
N
Neon22
Thu, Dec 29, 2016 2:25 AM

FYI
polgonal python based STL file unfolder:
https://github.com/osresearch/papercraft

--
View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19806.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

FYI polgonal python based STL file unfolder: https://github.com/osresearch/papercraft -- View this message in context: http://forum.openscad.org/flattening-curved-surfaces-tp19727p19806.html Sent from the OpenSCAD mailing list archive at Nabble.com.