discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Can you sweep a object with fingers

R
runsun
Tue, Nov 22, 2016 6:39 PM

Ronaldo wrote

Bezier curves are different: they interpolates just the first and last
control points and
they are in the convex hull of its control points.

In that case, I must have applied the Bezier in a wrong way. These curves
are indeed built with Bezier approach, but I applied it pair-wise (each pair
generates 4 CPs), so points between each pair are Bezier points.


$  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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19327.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ronaldo wrote > Bezier curves are different: they interpolates just the first and last > control points and > they are in the convex hull of its control points. In that case, I must have applied the Bezier in a wrong way. These curves are indeed built with Bezier approach, but I applied it pair-wise (each pair generates 4 CPs), so points between each pair are Bezier points. ----- $ 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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19327.html Sent from the OpenSCAD mailing list archive at Nabble.com.
RP
Ronaldo Persiano
Tue, Nov 22, 2016 7:11 PM

2016-11-22 16:39 GMT-02:00 runsun runsun@gmail.com:

In that case, I must have applied the Bezier in a wrong way. These curves
are indeed built with Bezier approach, but I applied it pair-wise (each
pair
generates 4 CPs), so points between each pair are Bezier points.

Ok, I see what you have done, you did right. It is a C1 interpolation

spline, sometimes called Hermite spline. You possibly estimates the
tangents at the points and find the Bezier CPs of each polynomial arc based
on the tangents and the extremes points of the arc. But then, the BezierCPs
are not all interpolated and two of them for each arc control the starting
end ending arc tangent. The same happens with Bezier CPs of surfaces: some
CPs are interpolated and the others control its partial derivatives.

2016-11-22 16:39 GMT-02:00 runsun <runsun@gmail.com>: > In that case, I must have applied the Bezier in a wrong way. These curves > are indeed built with Bezier approach, but I applied it pair-wise (each > pair > generates 4 CPs), so points between each pair are Bezier points. > > Ok, I see what you have done, you did right. It is a C1 interpolation spline, sometimes called Hermite spline. You possibly estimates the tangents at the points and find the Bezier CPs of each polynomial arc based on the tangents and the extremes points of the arc. But then, the BezierCPs are not all interpolated and two of them for each arc control the starting end ending arc tangent. The same happens with Bezier CPs of surfaces: some CPs are interpolated and the others control its partial derivatives.
R
Ronaldo
Tue, Nov 22, 2016 8:39 PM

runsun,

Perhaps, the following code may help you to understand the relationship
between the CPs and the Bezier triangle surface. You don't need to
understand all the code. Run it, change the first two or three parameters
and examine the results.

use
<Bezier_triangles.scad>
// this should be the previous code defining Tpatches

a = 45; // change freely this two parameters
b = 30; // this is a z scale
degree = 3; // and the polynomial degree up to 6
size = 50;  // of the base triangle

// base triangle vertices
base_tri = size*[ [1,0], [-1/2,sqrt(3)/2], [-1/2,-sqrt(3)/2] ];
// control points of a zero polynomial
bcps =  [ for(i=[degree:-1:0]) [for(j=[0:degree-i]) base_tri[0]*i/degree +
base_tri[1]j/degree +base_tri[2](degree-i-j)/degree ] ];

// Z values to be added to bcps
zvals = [ for(i=[5:(degree+2)(degree+1)/2+10]) b(sin(i*a)+2) ];
// the final control points
cps  = [for(i=[0:degree]) [for(j=[0:i]) [bcps[i][j][0], bcps[i][j][1],
zvals[i+(i-1)*i/2+j] ] ] ];

Tpatch_grid(bcps);
color("blue") Tpatch_grid(cps);
show_Tpatch(Bezier_Tpatch_mesh(cps, 10),c="red");
color("red") Tpatch_grid(Bezier_Tpatch_mesh(cps, 10),t=0.7);

module Tpatch_grid(tp, t=1) {
n = len(tp);
if (n>1) {
for(i=[1:n-1]) polyline(tp[i],t=t);
for(i=[1:n-1]) polyline([for(j=[0:i]) tp[n-j-1][i-j] ],t=t);
for(j=[0:n-2]) polyline([for(i=[j:n-1]) tp[i][j] ],t=t);
}
}

module polyline(pts, t=1, closed=false) {
if(len(pts)>1 && len(pts[0])>1 && t>0) {
p  = concat([for(ptsi=pts) project_to_3D(ptsi)],
closed? [project_to_3D(pts[0])] : []);
for(i=[0:len(p)-2]) {
v = p[i+1]-p[i];
h = norm(v);
if( h > 1e-12)
translate(p[i])
rotate([0, acos(v[2]/h), atan2(v[1],v[0])])
rotate(45) cylinder(h=h, d=t, $fn=4);
}
}
}

function project_to_3D(p) =
len(p)>=3? [p[0], p[1], p[2]] : len(p)==2 ? [p[0], p[1], 0] : [];

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19330.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

runsun, Perhaps, the following code may help you to understand the relationship between the CPs and the Bezier triangle surface. You don't need to understand all the code. Run it, change the first two or three parameters and examine the results. > use > <Bezier_triangles.scad> > // this should be the previous code defining Tpatches > > a = 45; // change freely this two parameters > b = 30; // this is a z scale > degree = 3; // and the polynomial degree up to 6 > size = 50; // of the base triangle > > // base triangle vertices > base_tri = size*[ [1,0], [-1/2,sqrt(3)/2], [-1/2,-sqrt(3)/2] ]; > // control points of a zero polynomial > bcps = [ for(i=[degree:-1:0]) [for(j=[0:degree-i]) base_tri[0]*i/degree + > base_tri[1]*j/degree +base_tri[2]*(degree-i-j)/degree ] ]; > > // Z values to be added to bcps > zvals = [ for(i=[5:(degree+2)*(degree+1)/2+10]) b*(sin(i*a)+2) ]; > // the final control points > cps = [for(i=[0:degree]) [for(j=[0:i]) [bcps[i][j][0], bcps[i][j][1], > zvals[i+(i-1)*i/2+j] ] ] ]; > > Tpatch_grid(bcps); > color("blue") Tpatch_grid(cps); > show_Tpatch(Bezier_Tpatch_mesh(cps, 10),c="red"); > color("red") Tpatch_grid(Bezier_Tpatch_mesh(cps, 10),t=0.7); > > module Tpatch_grid(tp, t=1) { > n = len(tp); > if (n>1) { > for(i=[1:n-1]) polyline(tp[i],t=t); > for(i=[1:n-1]) polyline([for(j=[0:i]) tp[n-j-1][i-j] ],t=t); > for(j=[0:n-2]) polyline([for(i=[j:n-1]) tp[i][j] ],t=t); > } > } > > module polyline(pts, t=1, closed=false) { > if(len(pts)>1 && len(pts[0])>1 && t>0) { > p = concat([for(ptsi=pts) project_to_3D(ptsi)], > closed? [project_to_3D(pts[0])] : []); > for(i=[0:len(p)-2]) { > v = p[i+1]-p[i]; > h = norm(v); > if( h > 1e-12) > translate(p[i]) > rotate([0, acos(v[2]/h), atan2(v[1],v[0])]) > rotate(45) cylinder(h=h, d=t, $fn=4); > } > } > } > > function project_to_3D(p) = > len(p)>=3? [p[0], p[1], p[2]] : len(p)==2 ? [p[0], p[1], 0] : []; -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19330.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Thu, Nov 24, 2016 12:43 AM

@ Ronaldo, Wow, this is cool. Thx man.


$  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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19347.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

@ Ronaldo, Wow, this is cool. Thx man. ----- $ 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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19347.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Thu, Nov 24, 2016 12:49 AM

Looking at the result shapes, I now understand how the Bezier Triangle Patch
manages to go from CPs to poly.

I guess it's a method to "generate a new surface", which is different from
"smoothing existing surface" that I originally imagined.


$  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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19348.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Looking at the result shapes, I now understand how the Bezier Triangle Patch manages to go from CPs to poly. I guess it's a method to "generate a new surface", which is different from "smoothing existing surface" that I originally imagined. ----- $ 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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19348.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
Ronaldo
Thu, Nov 24, 2016 4:12 AM

2016-11-23 22:49 GMT-02:00 runsun
<
runsun@gmail.com
>
:
I guess it's a method to "generate a new surface", which is different
from
"smoothing existing surface" that I originally imagined.

In some sense, Bezier curves and surfaces are a smoothing process of the
control points. Look at the following sequence of operations behind a Bezier
quadratic:
http://forum.openscad.org/file/n19354/Bez_subdivision.png

From left to right, the first figure shows the CPs (red marks) of a

quadratic arc: it has one corner point. In the second, we cut the corner
point out through the median points of the two edges and get 2 new green
corners. In the next one, we cut the two new corners by the same process and
get 4 new green corners. If we iterate indefinitely this process of cutting
corners, we will get a smooth curve (the blue one): a parabola! Note that
the median point of each new edge resulting from the corner cut (the blue
marks) is a point of the final parabola. The corner cutting method is a
smoothing process.

It is not what you originally imagined because it is not an interpolation
process. However, interpolation methods sometimes produce unexpected
oscillations, that is a waving behavior we don't see in the data points.
Even natural spline interpolation method is unstable. On the other hand,
Bezier and B-spline methods are not interpolations of their CPs but have no
more "oscillations" than their CPs. In CADGD, the Bezier and B-spline
representations are invaluable when we understand well the relationship
between the shapes and their CPs and realize why CPs are called as such.

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19354.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

> 2016-11-23 22:49 GMT-02:00 runsun > &lt; > runsun@gmail.com > &gt; > : > I guess it's a method to "generate a new surface", which is different > from > "smoothing existing surface" that I originally imagined. In some sense, Bezier curves and surfaces are a smoothing process of the control points. Look at the following sequence of operations behind a Bezier quadratic: <http://forum.openscad.org/file/n19354/Bez_subdivision.png> >From left to right, the first figure shows the CPs (red marks) of a quadratic arc: it has one corner point. In the second, we cut the corner point out through the median points of the two edges and get 2 new green corners. In the next one, we cut the two new corners by the same process and get 4 new green corners. If we iterate indefinitely this process of cutting corners, we will get a smooth curve (the blue one): a parabola! Note that the median point of each new edge resulting from the corner cut (the blue marks) is a point of the final parabola. The corner cutting method is a smoothing process. It is not what you originally imagined because it is not an interpolation process. However, interpolation methods sometimes produce unexpected oscillations, that is a waving behavior we don't see in the data points. Even natural spline interpolation method is unstable. On the other hand, Bezier and B-spline methods are not interpolations of their CPs but have no more "oscillations" than their CPs. In CADGD, the Bezier and B-spline representations are invaluable when we understand well the relationship between the shapes and their CPs and realize why CPs are called as such. -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19354.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Thu, Nov 24, 2016 2:07 PM

Thanks Ronaldo,

nice example. To cherish stuff like that an image of what the code produces
is invaluable:

http://forum.openscad.org/file/n19356/Unbenannt.png

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19356.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks Ronaldo, nice example. To cherish stuff like that an image of what the code produces is invaluable: <http://forum.openscad.org/file/n19356/Unbenannt.png> -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19356.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
Ronaldo
Mon, Nov 28, 2016 7:49 PM

I have found a family of methods appropriated to build organic shapes. They
are called subdivision algorithms and are founded in the subdivision methods
usual to Bezier and B-spline curve and surfaces. They may be regarded as a
generalization of the corner cutting method I illustrated in my previous
message.

Imagine you start with a cube. As a first step, we cut out each vertex of
the cube by a plane through its incident edges. Twenty four new vertices now
substitute the initial twelve and eighth new facets are added. Now, apply
the same procedure (vertex cuts) to the resulting polyhedron again and
again. The polyhedron facet number will grow exponentially and the
polyhedron surface may converge to a smooth surface depending on the chosen
cuts.

The methods I have found are different from that in the way they cut the
vertices but that is the general idea behind them. The methods are very
simple and could be well implemented in OpenSCAD if we had more powerful
means to build data structures. The iteration steps of the method require
that the polyhedron definition be refined.

I have started to write a triangulation data structure in OpenSCAD. But it
is very hard to do it with just lists and even harder to debug it.

Here are some references of papers on the subdivision methods:

Interpolating Nets Of Curves By Smooth Subdivision Surface
https://pdfs.semanticscholar.org/ab8d/1d77586beeedcb8808a21fb25cd0e2771a2a.pdf

Interpolatory sqrt(3)-subdivision
https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwiSoOD7mczQAhVBgpAKHUzLCzMQFggmMAE&url=http%3A%2F%2Fwww.uni-weimar.de%2F~caw%2Fpapers%2Fgreiner.pdf&usg=AFQjCNE-OqH_GOxWnHqo1uAdI1dS8x7uiw&sig2=z4lHuTty2O0MgmogO-plIw&bvm=bv.139782543,d.Y2I

sqrt(3)-subdivision
https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiA94aZmszQAhUBjZAKHZnRBuIQFggbMAA&url=https%3A%2F%2Fwww.graphics.rwth-aachen.de%2Fmedia%2Fpapers%2Fsqrt31.pdf&usg=AFQjCNEuF9Yzqs9sJ3EqFO5pO0-j3WJ38A&sig2=y5GcfkkyMEIx57EdqE89pg&bvm=bv.139782543,d.Y2I

The first reference have nice figures showing how promising is the method
for organic modelling.

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19390.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I have found a family of methods appropriated to build organic shapes. They are called subdivision algorithms and are founded in the subdivision methods usual to Bezier and B-spline curve and surfaces. They may be regarded as a generalization of the corner cutting method I illustrated in my previous message. Imagine you start with a cube. As a first step, we cut out each vertex of the cube by a plane through its incident edges. Twenty four new vertices now substitute the initial twelve and eighth new facets are added. Now, apply the same procedure (vertex cuts) to the resulting polyhedron again and again. The polyhedron facet number will grow exponentially and the polyhedron surface may converge to a smooth surface depending on the chosen cuts. The methods I have found are different from that in the way they cut the vertices but that is the general idea behind them. The methods are very simple and could be well implemented in OpenSCAD if we had more powerful means to build data structures. The iteration steps of the method require that the polyhedron definition be refined. I have started to write a triangulation data structure in OpenSCAD. But it is very hard to do it with just lists and even harder to debug it. Here are some references of papers on the subdivision methods: Interpolating Nets Of Curves By Smooth Subdivision Surface <https://pdfs.semanticscholar.org/ab8d/1d77586beeedcb8808a21fb25cd0e2771a2a.pdf> Interpolatory sqrt(3)-subdivision <https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0ahUKEwiSoOD7mczQAhVBgpAKHUzLCzMQFggmMAE&url=http%3A%2F%2Fwww.uni-weimar.de%2F~caw%2Fpapers%2Fgreiner.pdf&usg=AFQjCNE-OqH_GOxWnHqo1uAdI1dS8x7uiw&sig2=z4lHuTty2O0MgmogO-plIw&bvm=bv.139782543,d.Y2I> sqrt(3)-subdivision <https://www.google.com.br/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiA94aZmszQAhUBjZAKHZnRBuIQFggbMAA&url=https%3A%2F%2Fwww.graphics.rwth-aachen.de%2Fmedia%2Fpapers%2Fsqrt31.pdf&usg=AFQjCNEuF9Yzqs9sJ3EqFO5pO0-j3WJ38A&sig2=y5GcfkkyMEIx57EdqE89pg&bvm=bv.139782543,d.Y2I> The first reference have nice figures showing how promising is the method for organic modelling. -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19390.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Mon, Nov 28, 2016 9:24 PM

@Ronaldo, Thx for the precious references.

Btw, I saw you mentioned data structure in several posts. What do you have
in mind ?


$  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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19393.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

@Ronaldo, Thx for the precious references. Btw, I saw you mentioned data structure in several posts. What do you have in mind ? ----- $ 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 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text , triang , unit ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19393.html Sent from the OpenSCAD mailing list archive at Nabble.com.
N
Neon22
Mon, Nov 28, 2016 10:00 PM

@ronaldo -  don't forget the doo-sabin resmooth operator which is very
useful.
It can be easily seen in Wings3D under the Bodies menu. Where you can also
compare it to the regular smooth algorithm.

--
View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19396.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

@ronaldo - don't forget the doo-sabin resmooth operator which is very useful. It can be easily seen in Wings3D under the Bodies menu. Where you can also compare it to the regular smooth algorithm. -- View this message in context: http://forum.openscad.org/Can-you-sweep-a-object-with-fingers-tp19057p19396.html Sent from the OpenSCAD mailing list archive at Nabble.com.