discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Modelling a flexible strip

NH
nop head
Sun, Dec 24, 2017 7:59 PM

However, I don't believe the shape of a bent physical strip in a general

setting may be modeled by a cubic arc.

Yes that seems to be the case despite computer splines having their origin
in physical splines. I am surprised there isn't an off the shelf solution
for a uniform strip because I don't think the shape depends on anything
other than the length and the endpoint position and orientation. I.e. I
don't think it depends on its stiffness.

On 24 December 2017 at 19:28, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

You are right. The expression of the energy I've been using is an
approximation of the bending energy valid only under some strict
conditions. As its integral is easily evaluated it is the usual energy
expression in the context of geometric modeling.

You need a physical bending energy though and that may be computed with a
little more effort applying the expression of curvature found in
https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a
suitable subdivision refinement of the curve.

​I believe the energy minimizing strategy I devised may still work with
the bending energy based on curvature.

However, I don't believe the shape of a bent physical strip in a general
setting may be modeled by a cubic arc.

2017-12-22 17:51 GMT-02:00 nop head nop.head@gmail.com:

The energy expression of a curve was taken proportional to the integral

of its second parametric derivative

I don't think this is right. I think the energy is proportional to the
integral of the square of curvature. This is because the potential energy
in a spring is a square law due to the force increasing as you bend it.

Also I think curvature is second derivative with respect to arc length,
not the parameter.

>However, I don't believe the shape of a bent physical strip in a general setting may be modeled by a cubic arc. Yes that seems to be the case despite computer splines having their origin in physical splines. I am surprised there isn't an off the shelf solution for a uniform strip because I don't think the shape depends on anything other than the length and the endpoint position and orientation. I.e. I don't think it depends on its stiffness. On 24 December 2017 at 19:28, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > You are right. The expression of the energy I've been using is an > approximation of the bending energy valid only under some strict > conditions. As its integral is easily evaluated it is the usual energy > expression in the context of geometric modeling. > > You need a physical bending energy though and that may be computed with a > little more effort applying the expression of curvature found in > https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a > suitable subdivision refinement of the curve. > > ​I believe the energy minimizing strategy I devised may still work with > the bending energy based on curvature. > > However, I don't believe the shape of a bent physical strip in a general > setting may be modeled by a cubic arc. > > 2017-12-22 17:51 GMT-02:00 nop head <nop.head@gmail.com>: > >> >The energy expression of a curve was taken proportional to the integral >> of its second parametric derivative >> >> I don't think this is right. I think the energy is proportional to the >> integral of the square of curvature. This is because the potential energy >> in a spring is a square law due to the force increasing as you bend it. >> >> Also I think curvature is second derivative with respect to arc length, >> not the parameter. >> >> >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
DS
Dan Shriver
Sun, Dec 24, 2017 11:52 PM

If the ends are not "close" doesn't a catenary come very near to the actual
solution? I agree it goes out the window if the two ends are close.

On Sunday, December 24, 2017, nop head nop.head@gmail.com wrote:

However, I don't believe the shape of a bent physical strip in a general

setting may be modeled by a cubic arc.

Yes that seems to be the case despite computer splines having their origin
in physical splines. I am surprised there isn't an off the shelf solution
for a uniform strip because I don't think the shape depends on anything
other than the length and the endpoint position and orientation. I.e. I
don't think it depends on its stiffness.

On 24 December 2017 at 19:28, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

You are right. The expression of the energy I've been using is an
approximation of the bending energy valid only under some strict
conditions. As its integral is easily evaluated it is the usual energy
expression in the context of geometric modeling.

You need a physical bending energy though and that may be computed with a
little more effort applying the expression of curvature found in
https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a
suitable subdivision refinement of the curve.

​I believe the energy minimizing strategy I devised may still work with
the bending energy based on curvature.

However, I don't believe the shape of a bent physical strip in a general
setting may be modeled by a cubic arc.

2017-12-22 17:51 GMT-02:00 nop head nop.head@gmail.com:

The energy expression of a curve was taken proportional to the integral

of its second parametric derivative

I don't think this is right. I think the energy is proportional to the
integral of the square of curvature. This is because the potential energy
in a spring is a square law due to the force increasing as you bend it.

Also I think curvature is second derivative with respect to arc length,
not the parameter.

If the ends are not "close" doesn't a catenary come very near to the actual solution? I agree it goes out the window if the two ends are close. On Sunday, December 24, 2017, nop head <nop.head@gmail.com> wrote: > >However, I don't believe the shape of a bent physical strip in a general > setting may be modeled by a cubic arc. > > Yes that seems to be the case despite computer splines having their origin > in physical splines. I am surprised there isn't an off the shelf solution > for a uniform strip because I don't think the shape depends on anything > other than the length and the endpoint position and orientation. I.e. I > don't think it depends on its stiffness. > > On 24 December 2017 at 19:28, Ronaldo Persiano <rcmpersiano@gmail.com> > wrote: > >> You are right. The expression of the energy I've been using is an >> approximation of the bending energy valid only under some strict >> conditions. As its integral is easily evaluated it is the usual energy >> expression in the context of geometric modeling. >> >> You need a physical bending energy though and that may be computed with a >> little more effort applying the expression of curvature found in >> https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a >> suitable subdivision refinement of the curve. >> >> ​I believe the energy minimizing strategy I devised may still work with >> the bending energy based on curvature. >> >> However, I don't believe the shape of a bent physical strip in a general >> setting may be modeled by a cubic arc. >> >> 2017-12-22 17:51 GMT-02:00 nop head <nop.head@gmail.com>: >> >>> >The energy expression of a curve was taken proportional to the integral >>> of its second parametric derivative >>> >>> I don't think this is right. I think the energy is proportional to the >>> integral of the square of curvature. This is because the potential energy >>> in a spring is a square law due to the force increasing as you bend it. >>> >>> Also I think curvature is second derivative with respect to arc length, >>> not the parameter. >>> >>> >>> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >
NH
nop head
Mon, Dec 25, 2017 12:02 AM

I don't think so. A catenary forms under gravity with an infinitely
flexible cord. It is all about tension along the tangent rather than
curvature causing stress forces. The equation is a simple integral we did
at school. I don't think the minimum energy curve has a simple mathematical
formula.

On 24 December 2017 at 23:52, Dan Shriver tabbydan@gmail.com wrote:

If the ends are not "close" doesn't a catenary come very near to the
actual solution? I agree it goes out the window if the two ends are close.

On Sunday, December 24, 2017, nop head nop.head@gmail.com wrote:

However, I don't believe the shape of a bent physical strip in a general

setting may be modeled by a cubic arc.

Yes that seems to be the case despite computer splines having their
origin in physical splines. I am surprised there isn't an off the shelf
solution for a uniform strip because I don't think the shape depends on
anything other than the length and the endpoint position and orientation.
I.e. I don't think it depends on its stiffness.

On 24 December 2017 at 19:28, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

You are right. The expression of the energy I've been using is an
approximation of the bending energy valid only under some strict
conditions. As its integral is easily evaluated it is the usual energy
expression in the context of geometric modeling.

You need a physical bending energy though and that may be computed with
a little more effort applying the expression of curvature found in
https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a
suitable subdivision refinement of the curve.

​I believe the energy minimizing strategy I devised may still work with
the bending energy based on curvature.

However, I don't believe the shape of a bent physical strip in a general
setting may be modeled by a cubic arc.

2017-12-22 17:51 GMT-02:00 nop head nop.head@gmail.com:

The energy expression of a curve was taken proportional to the

integral of its second parametric derivative

I don't think this is right. I think the energy is proportional to the
integral of the square of curvature. This is because the potential energy
in a spring is a square law due to the force increasing as you bend it.

Also I think curvature is second derivative with respect to arc length,
not the parameter.

I don't think so. A catenary forms under gravity with an infinitely flexible cord. It is all about tension along the tangent rather than curvature causing stress forces. The equation is a simple integral we did at school. I don't think the minimum energy curve has a simple mathematical formula. On 24 December 2017 at 23:52, Dan Shriver <tabbydan@gmail.com> wrote: > If the ends are not "close" doesn't a catenary come very near to the > actual solution? I agree it goes out the window if the two ends are close. > > > On Sunday, December 24, 2017, nop head <nop.head@gmail.com> wrote: > >> >However, I don't believe the shape of a bent physical strip in a general >> setting may be modeled by a cubic arc. >> >> Yes that seems to be the case despite computer splines having their >> origin in physical splines. I am surprised there isn't an off the shelf >> solution for a uniform strip because I don't think the shape depends on >> anything other than the length and the endpoint position and orientation. >> I.e. I don't think it depends on its stiffness. >> >> On 24 December 2017 at 19:28, Ronaldo Persiano <rcmpersiano@gmail.com> >> wrote: >> >>> You are right. The expression of the energy I've been using is an >>> approximation of the bending energy valid only under some strict >>> conditions. As its integral is easily evaluated it is the usual energy >>> expression in the context of geometric modeling. >>> >>> You need a physical bending energy though and that may be computed with >>> a little more effort applying the expression of curvature found in >>> https://en.wikipedia.org/wiki/Curvature#Curvature_of_space_curves to a >>> suitable subdivision refinement of the curve. >>> >>> ​I believe the energy minimizing strategy I devised may still work with >>> the bending energy based on curvature. >>> >>> However, I don't believe the shape of a bent physical strip in a general >>> setting may be modeled by a cubic arc. >>> >>> 2017-12-22 17:51 GMT-02:00 nop head <nop.head@gmail.com>: >>> >>>> >The energy expression of a curve was taken proportional to the >>>> integral of its second parametric derivative >>>> >>>> I don't think this is right. I think the energy is proportional to the >>>> integral of the square of curvature. This is because the potential energy >>>> in a spring is a square law due to the force increasing as you bend it. >>>> >>>> Also I think curvature is second derivative with respect to arc length, >>>> not the parameter. >>>> >>>> >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
RP
Ronaldo Persiano
Mon, Dec 25, 2017 5:31 PM

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of an
iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic energy
against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping the
two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version with
the control points equidistant below the end points.

Here is the code of my atempts to find the cubic with minimum energy. First note that AdjustBezier() finds the cubic with the desired length keeping the balance between the norms of the cubic endpoint derivatives. The strategy I used in the code was to change this balance in order to reduce the cubic energy. // for any cubic bz, it holds bz == balance(bz, 0.5) function balance(bz,s) = [ bz[0], bz[0] + 2*s*(bz[1]-bz[0]), bz[3] + 2*(1-s)*(bz[2]-bz[3]), bz[3] ]; For each balance, the cubic is adjusted to the target length by AdjustBezier() and its energy is calculated. function BalancedEnergy(bz, s, l, eps) = BzEnergy(AdjustBezier(balance(bz,s), l, eps)); To find the balance that leads to the minimum energy is objective of an iterative search. The search for the cubic with minimum energy is done iteratively narrowing an interval (s1,s2) of balances that contains the best balance. // Minimum energy Bezier arc with a given length l // and given tangent directions at its ends function BestBz(bz, l, eps=1e-3) = let( bz2 = [ bz[0], // normalize end derivatives bz[0]+unit(bz[1]-bz[0]), bz[3]+unit(bz[2]-bz[3]), bz[3] ], s1 = eps, en1 = BalancedEnergy(bz, s1, l, eps), en2 = BalancedEnergy(bz, 1-s1, l, eps), s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) echo(smin=s) AdjustBezier(balance(bz2,s), l); function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = let( s12 = (s1+s2)/2, e12 = BalancedEnergy(bz, s12, l, eps)) //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) abs(e12-(e1+e2)/2)/e12< eps ? e1<e2 ? s1 : s2 : let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? s3 : let( e3 = BalancedEnergy(bz, s3, l, eps) ) //echo(e3=e3) abs(e3-e12)/e12<eps ? s3 : e3<e12 ? s3<s12 ? _bestS(bz,l,s1,s12,e1,e12,eps,n-1) : _bestS(bz,l,s12,s2,e12,e2,eps,n-1) : s3<s12 ? _bestS(bz,l,s3,s2,e3,e2,eps,n-1) : _bestS(bz,l,s1,s3,e1,e3,eps,n-1); The full code is annexed. In the experiments I have done with the code, the plot of the cubic energy against the balance parameter s has the shape of an U with an almost horizontal bottom. This shows that the effect of medium-sized changes of the optimal balance does not produce significant changes of the cubic energy. In special, in your case of a strip going down from a fixed pole to a moving table clamped point, the optimal balance will change slowly from 0.5 (when the two end points are level) to 1 (when the strip is fully stretched). That means the balance of the cubic endpoint derivatives in the optimal solution is slightly favorable to the fixed point if the strip is never fully stretched. So, your assumption that "keeping the two inner control points level" would do the trick is not confirmed by my results. 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: > I don't know if this has a mathematical validity but simple keeping the > two inner control points level with each other seems to produce a curve > that matches a strip held against the screen fairly well. > ​ > The length of the strip is only 9mm longer compared to the version with > the control points equidistant below the end points. > >
NH
nop head
Tue, Dec 26, 2017 2:17 PM

Interesting. I will have to combine with my code and put them side by side.
If I put my length and dimension into your code the result looks a lot
tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of an
iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic energy
against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping the
two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version with
the control points equidistant below the end points.

Interesting. I will have to combine with my code and put them side by side. If I put my length and dimension into your code the result looks a lot tighter and doesn't match what my real strip does. On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > Here is the code of my atempts to find the cubic with minimum energy. > > First note that AdjustBezier() finds the cubic with the desired length > keeping the balance between the norms of the cubic endpoint derivatives. > The strategy I used in the code was to change this balance in order to > reduce the cubic energy. > > // for any cubic bz, it holds bz == balance(bz, 0.5) > function balance(bz,s) = > [ bz[0], > bz[0] + 2*s*(bz[1]-bz[0]), > bz[3] + 2*(1-s)*(bz[2]-bz[3]), > bz[3] ]; > > > For each balance, the cubic is adjusted to the target length by > AdjustBezier() and its energy is calculated. > > function BalancedEnergy(bz, s, l, eps) = > BzEnergy(AdjustBezier(balance(bz,s), l, eps)); > > > To find the balance that leads to the minimum energy is objective of an > iterative search. The search for the cubic with minimum energy is done > iteratively narrowing an interval (s1,s2) of balances that contains the > best balance. > > // Minimum energy Bezier arc with a given length l > // and given tangent directions at its ends > function BestBz(bz, l, eps=1e-3) = > let( bz2 = [ bz[0], // normalize end derivatives > bz[0]+unit(bz[1]-bz[0]), > bz[3]+unit(bz[2]-bz[3]), > bz[3] ], > s1 = eps, > en1 = BalancedEnergy(bz, s1, l, eps), > en2 = BalancedEnergy(bz, 1-s1, l, eps), > s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) > echo(smin=s) > AdjustBezier(balance(bz2,s), l); > > function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = > let( s12 = (s1+s2)/2, > e12 = BalancedEnergy(bz, s12, l, eps)) > //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) > abs(e12-(e1+e2)/2)/e12< eps ? > e1<e2 ? s1 : s2 > : > let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) > //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) > abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? > s3 > : > let( e3 = BalancedEnergy(bz, s3, l, eps) ) > //echo(e3=e3) > abs(e3-e12)/e12<eps ? > s3 : > e3<e12 ? > s3<s12 ? > _bestS(bz,l,s1,s12,e1,e12,eps,n-1) > : > _bestS(bz,l,s12,s2,e12,e2,eps,n-1) > : > s3<s12 ? > _bestS(bz,l,s3,s2,e3,e2,eps,n-1) > : > _bestS(bz,l,s1,s3,e1,e3,eps,n-1); > > > The full code is annexed. > > In the experiments I have done with the code, the plot of the cubic energy > against the balance parameter s has the shape of an U with an almost > horizontal bottom. This shows that the effect of medium-sized changes of > the optimal balance does not produce significant changes of the cubic > energy. In special, in your case of a strip going down from a fixed pole to > a moving table clamped point, the optimal balance will change slowly from > 0.5 (when the two end points are level) to 1 (when the strip is fully > stretched). That means the balance of the cubic endpoint derivatives in the > optimal solution is slightly favorable to the fixed point if the strip is > never fully stretched. So, your assumption that "keeping the two inner > control points level" would do the trick is not confirmed by my results. > > 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: > >> I don't know if this has a mathematical validity but simple keeping the >> two inner control points level with each other seems to produce a curve >> that matches a strip held against the screen fairly well. >> ​ >> The length of the strip is only 9mm longer compared to the version with >> the control points equidistant below the end points. >> >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Tue, Dec 26, 2017 3:31 PM

Here is my curve in red and its control points in blue alongside yours with
my actual geometry. Your BzEnergy function returns 12 times the energy for
mine which is hard to believe because mine has a more distributed
curvature. A strip held against the screen follows mine, not yours, so I
think there must be a bug in your energy function.

On 26 December 2017 at 14:17, nop head nop.head@gmail.com wrote:

Interesting. I will have to combine with my code and put them side by
side. If I put my length and dimension into your code the result looks a
lot tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of an
iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic
energy against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping the
two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version with
the control points equidistant below the end points.

Here is my curve in red and its control points in blue alongside yours with my actual geometry. Your BzEnergy function returns 12 times the energy for mine which is hard to believe because mine has a more distributed curvature. A strip held against the screen follows mine, not yours, so I think there must be a bug in your energy function. On 26 December 2017 at 14:17, nop head <nop.head@gmail.com> wrote: > Interesting. I will have to combine with my code and put them side by > side. If I put my length and dimension into your code the result looks a > lot tighter and doesn't match what my real strip does. > > On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> > wrote: > >> Here is the code of my atempts to find the cubic with minimum energy. >> >> First note that AdjustBezier() finds the cubic with the desired length >> keeping the balance between the norms of the cubic endpoint derivatives. >> The strategy I used in the code was to change this balance in order to >> reduce the cubic energy. >> >> // for any cubic bz, it holds bz == balance(bz, 0.5) >> function balance(bz,s) = >> [ bz[0], >> bz[0] + 2*s*(bz[1]-bz[0]), >> bz[3] + 2*(1-s)*(bz[2]-bz[3]), >> bz[3] ]; >> >> >> For each balance, the cubic is adjusted to the target length by >> AdjustBezier() and its energy is calculated. >> >> function BalancedEnergy(bz, s, l, eps) = >> BzEnergy(AdjustBezier(balance(bz,s), l, eps)); >> >> >> To find the balance that leads to the minimum energy is objective of an >> iterative search. The search for the cubic with minimum energy is done >> iteratively narrowing an interval (s1,s2) of balances that contains the >> best balance. >> >> // Minimum energy Bezier arc with a given length l >> // and given tangent directions at its ends >> function BestBz(bz, l, eps=1e-3) = >> let( bz2 = [ bz[0], // normalize end derivatives >> bz[0]+unit(bz[1]-bz[0]), >> bz[3]+unit(bz[2]-bz[3]), >> bz[3] ], >> s1 = eps, >> en1 = BalancedEnergy(bz, s1, l, eps), >> en2 = BalancedEnergy(bz, 1-s1, l, eps), >> s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) >> echo(smin=s) >> AdjustBezier(balance(bz2,s), l); >> >> function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = >> let( s12 = (s1+s2)/2, >> e12 = BalancedEnergy(bz, s12, l, eps)) >> //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) >> abs(e12-(e1+e2)/2)/e12< eps ? >> e1<e2 ? s1 : s2 >> : >> let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) >> //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) >> abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? >> s3 >> : >> let( e3 = BalancedEnergy(bz, s3, l, eps) ) >> //echo(e3=e3) >> abs(e3-e12)/e12<eps ? >> s3 : >> e3<e12 ? >> s3<s12 ? >> _bestS(bz,l,s1,s12,e1,e12,eps,n-1) >> : >> _bestS(bz,l,s12,s2,e12,e2,eps,n-1) >> : >> s3<s12 ? >> _bestS(bz,l,s3,s2,e3,e2,eps,n-1) >> : >> _bestS(bz,l,s1,s3,e1,e3,eps,n-1); >> >> >> The full code is annexed. >> >> In the experiments I have done with the code, the plot of the cubic >> energy against the balance parameter s has the shape of an U with an almost >> horizontal bottom. This shows that the effect of medium-sized changes of >> the optimal balance does not produce significant changes of the cubic >> energy. In special, in your case of a strip going down from a fixed pole to >> a moving table clamped point, the optimal balance will change slowly from >> 0.5 (when the two end points are level) to 1 (when the strip is fully >> stretched). That means the balance of the cubic endpoint derivatives in the >> optimal solution is slightly favorable to the fixed point if the strip is >> never fully stretched. So, your assumption that "keeping the two inner >> control points level" would do the trick is not confirmed by my results. >> >> 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: >> >>> I don't know if this has a mathematical validity but simple keeping the >>> two inner control points level with each other seems to produce a curve >>> that matches a strip held against the screen fairly well. >>> ​ >>> The length of the strip is only 9mm longer compared to the version with >>> the control points equidistant below the end points. >>> >>> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >
NH
nop head
Tue, Dec 26, 2017 3:32 PM

Whoops

On 26 December 2017 at 15:31, nop head nop.head@gmail.com wrote:

Here is my curve in red and its control points in blue alongside yours
with my actual geometry. Your BzEnergy function returns 12 times the energy
for mine which is hard to believe because mine has a more distributed
curvature. A strip held against the screen follows mine, not yours, so I
think there must be a bug in your energy function.

On 26 December 2017 at 14:17, nop head nop.head@gmail.com wrote:

Interesting. I will have to combine with my code and put them side by
side. If I put my length and dimension into your code the result looks a
lot tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of an
iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic
energy against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping the
two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version with
the control points equidistant below the end points.

Whoops ​ On 26 December 2017 at 15:31, nop head <nop.head@gmail.com> wrote: > Here is my curve in red and its control points in blue alongside yours > with my actual geometry. Your BzEnergy function returns 12 times the energy > for mine which is hard to believe because mine has a more distributed > curvature. A strip held against the screen follows mine, not yours, so I > think there must be a bug in your energy function. > > On 26 December 2017 at 14:17, nop head <nop.head@gmail.com> wrote: > >> Interesting. I will have to combine with my code and put them side by >> side. If I put my length and dimension into your code the result looks a >> lot tighter and doesn't match what my real strip does. >> >> On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> >> wrote: >> >>> Here is the code of my atempts to find the cubic with minimum energy. >>> >>> First note that AdjustBezier() finds the cubic with the desired length >>> keeping the balance between the norms of the cubic endpoint derivatives. >>> The strategy I used in the code was to change this balance in order to >>> reduce the cubic energy. >>> >>> // for any cubic bz, it holds bz == balance(bz, 0.5) >>> function balance(bz,s) = >>> [ bz[0], >>> bz[0] + 2*s*(bz[1]-bz[0]), >>> bz[3] + 2*(1-s)*(bz[2]-bz[3]), >>> bz[3] ]; >>> >>> >>> For each balance, the cubic is adjusted to the target length by >>> AdjustBezier() and its energy is calculated. >>> >>> function BalancedEnergy(bz, s, l, eps) = >>> BzEnergy(AdjustBezier(balance(bz,s), l, eps)); >>> >>> >>> To find the balance that leads to the minimum energy is objective of an >>> iterative search. The search for the cubic with minimum energy is done >>> iteratively narrowing an interval (s1,s2) of balances that contains the >>> best balance. >>> >>> // Minimum energy Bezier arc with a given length l >>> // and given tangent directions at its ends >>> function BestBz(bz, l, eps=1e-3) = >>> let( bz2 = [ bz[0], // normalize end derivatives >>> bz[0]+unit(bz[1]-bz[0]), >>> bz[3]+unit(bz[2]-bz[3]), >>> bz[3] ], >>> s1 = eps, >>> en1 = BalancedEnergy(bz, s1, l, eps), >>> en2 = BalancedEnergy(bz, 1-s1, l, eps), >>> s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) >>> echo(smin=s) >>> AdjustBezier(balance(bz2,s), l); >>> >>> function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = >>> let( s12 = (s1+s2)/2, >>> e12 = BalancedEnergy(bz, s12, l, eps)) >>> //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) >>> abs(e12-(e1+e2)/2)/e12< eps ? >>> e1<e2 ? s1 : s2 >>> : >>> let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) >>> //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) >>> abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? >>> s3 >>> : >>> let( e3 = BalancedEnergy(bz, s3, l, eps) ) >>> //echo(e3=e3) >>> abs(e3-e12)/e12<eps ? >>> s3 : >>> e3<e12 ? >>> s3<s12 ? >>> _bestS(bz,l,s1,s12,e1,e12,eps,n-1) >>> : >>> _bestS(bz,l,s12,s2,e12,e2,eps,n-1) >>> : >>> s3<s12 ? >>> _bestS(bz,l,s3,s2,e3,e2,eps,n-1) >>> : >>> _bestS(bz,l,s1,s3,e1,e3,eps,n-1); >>> >>> >>> The full code is annexed. >>> >>> In the experiments I have done with the code, the plot of the cubic >>> energy against the balance parameter s has the shape of an U with an almost >>> horizontal bottom. This shows that the effect of medium-sized changes of >>> the optimal balance does not produce significant changes of the cubic >>> energy. In special, in your case of a strip going down from a fixed pole to >>> a moving table clamped point, the optimal balance will change slowly from >>> 0.5 (when the two end points are level) to 1 (when the strip is fully >>> stretched). That means the balance of the cubic endpoint derivatives in the >>> optimal solution is slightly favorable to the fixed point if the strip is >>> never fully stretched. So, your assumption that "keeping the two inner >>> control points level" would do the trick is not confirmed by my results. >>> >>> 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: >>> >>>> I don't know if this has a mathematical validity but simple keeping the >>>> two inner control points level with each other seems to produce a curve >>>> that matches a strip held against the screen fairly well. >>>> ​ >>>> The length of the strip is only 9mm longer compared to the version with >>>> the control points equidistant below the end points. >>>> >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >> >
RP
Ronaldo Persiano
Tue, Dec 26, 2017 4:15 PM

Would you mind to provide me the geometric data (endpoint coordinates and
strip length) of this case?

2017-12-26 13:32 GMT-02:00 nop head nop.head@gmail.com:

Whoops

On 26 December 2017 at 15:31, nop head nop.head@gmail.com wrote:

Here is my curve in red and its control points in blue alongside yours
with my actual geometry. Your BzEnergy function returns 12 times the energy
for mine which is hard to believe because mine has a more distributed
curvature. A strip held against the screen follows mine, not yours, so I
think there must be a bug in your energy function.

On 26 December 2017 at 14:17, nop head nop.head@gmail.com wrote:

Interesting. I will have to combine with my code and put them side by
side. If I put my length and dimension into your code the result looks a
lot tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of an
iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic
energy against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping
the two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version
with the control points equidistant below the end points.

Would you mind to provide me the geometric data (endpoint coordinates and strip length) of this case? 2017-12-26 13:32 GMT-02:00 nop head <nop.head@gmail.com>: > Whoops > > > ​ > > On 26 December 2017 at 15:31, nop head <nop.head@gmail.com> wrote: > >> Here is my curve in red and its control points in blue alongside yours >> with my actual geometry. Your BzEnergy function returns 12 times the energy >> for mine which is hard to believe because mine has a more distributed >> curvature. A strip held against the screen follows mine, not yours, so I >> think there must be a bug in your energy function. >> >> On 26 December 2017 at 14:17, nop head <nop.head@gmail.com> wrote: >> >>> Interesting. I will have to combine with my code and put them side by >>> side. If I put my length and dimension into your code the result looks a >>> lot tighter and doesn't match what my real strip does. >>> >>> On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> >>> wrote: >>> >>>> Here is the code of my atempts to find the cubic with minimum energy. >>>> >>>> First note that AdjustBezier() finds the cubic with the desired length >>>> keeping the balance between the norms of the cubic endpoint derivatives. >>>> The strategy I used in the code was to change this balance in order to >>>> reduce the cubic energy. >>>> >>>> // for any cubic bz, it holds bz == balance(bz, 0.5) >>>> function balance(bz,s) = >>>> [ bz[0], >>>> bz[0] + 2*s*(bz[1]-bz[0]), >>>> bz[3] + 2*(1-s)*(bz[2]-bz[3]), >>>> bz[3] ]; >>>> >>>> >>>> For each balance, the cubic is adjusted to the target length by >>>> AdjustBezier() and its energy is calculated. >>>> >>>> function BalancedEnergy(bz, s, l, eps) = >>>> BzEnergy(AdjustBezier(balance(bz,s), l, eps)); >>>> >>>> >>>> To find the balance that leads to the minimum energy is objective of an >>>> iterative search. The search for the cubic with minimum energy is done >>>> iteratively narrowing an interval (s1,s2) of balances that contains the >>>> best balance. >>>> >>>> // Minimum energy Bezier arc with a given length l >>>> // and given tangent directions at its ends >>>> function BestBz(bz, l, eps=1e-3) = >>>> let( bz2 = [ bz[0], // normalize end derivatives >>>> bz[0]+unit(bz[1]-bz[0]), >>>> bz[3]+unit(bz[2]-bz[3]), >>>> bz[3] ], >>>> s1 = eps, >>>> en1 = BalancedEnergy(bz, s1, l, eps), >>>> en2 = BalancedEnergy(bz, 1-s1, l, eps), >>>> s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) >>>> echo(smin=s) >>>> AdjustBezier(balance(bz2,s), l); >>>> >>>> function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = >>>> let( s12 = (s1+s2)/2, >>>> e12 = BalancedEnergy(bz, s12, l, eps)) >>>> //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) >>>> abs(e12-(e1+e2)/2)/e12< eps ? >>>> e1<e2 ? s1 : s2 >>>> : >>>> let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) >>>> //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) >>>> abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? >>>> s3 >>>> : >>>> let( e3 = BalancedEnergy(bz, s3, l, eps) ) >>>> //echo(e3=e3) >>>> abs(e3-e12)/e12<eps ? >>>> s3 : >>>> e3<e12 ? >>>> s3<s12 ? >>>> _bestS(bz,l,s1,s12,e1,e12,eps,n-1) >>>> : >>>> _bestS(bz,l,s12,s2,e12,e2,eps,n-1) >>>> : >>>> s3<s12 ? >>>> _bestS(bz,l,s3,s2,e3,e2,eps,n-1) >>>> : >>>> _bestS(bz,l,s1,s3,e1,e3,eps,n-1); >>>> >>>> >>>> The full code is annexed. >>>> >>>> In the experiments I have done with the code, the plot of the cubic >>>> energy against the balance parameter s has the shape of an U with an almost >>>> horizontal bottom. This shows that the effect of medium-sized changes of >>>> the optimal balance does not produce significant changes of the cubic >>>> energy. In special, in your case of a strip going down from a fixed pole to >>>> a moving table clamped point, the optimal balance will change slowly from >>>> 0.5 (when the two end points are level) to 1 (when the strip is fully >>>> stretched). That means the balance of the cubic endpoint derivatives in the >>>> optimal solution is slightly favorable to the fixed point if the strip is >>>> never fully stretched. So, your assumption that "keeping the two inner >>>> control points level" would do the trick is not confirmed by my results. >>>> >>>> 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: >>>> >>>>> I don't know if this has a mathematical validity but simple keeping >>>>> the two inner control points level with each other seems to produce a curve >>>>> that matches a strip held against the screen fairly well. >>>>> ​ >>>>> The length of the strip is only 9mm longer compared to the version >>>>> with the control points equidistant below the end points. >>>>> >>>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> Discuss@lists.openscad.org >>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>> >>>> >>> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
NH
nop head
Tue, Dec 26, 2017 4:21 PM

The starting point is:

bzcp=[[0, 0, 0], [0, 0, -125.85], [0, 79.721, -125.85], [0, 79.721,
-108.35]];
length=180;

After I adjust the control points for length I get  [[0, 0, 0], [0, 0,
-139.685], [0, 79.721, -139.685], [0, 79.721, -108.35]]

On 26 December 2017 at 16:15, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Would you mind to provide me the geometric data (endpoint coordinates and
strip length) of this case?

2017-12-26 13:32 GMT-02:00 nop head nop.head@gmail.com:

Whoops

On 26 December 2017 at 15:31, nop head nop.head@gmail.com wrote:

Here is my curve in red and its control points in blue alongside yours
with my actual geometry. Your BzEnergy function returns 12 times the energy
for mine which is hard to believe because mine has a more distributed
curvature. A strip held against the screen follows mine, not yours, so I
think there must be a bug in your energy function.

On 26 December 2017 at 14:17, nop head nop.head@gmail.com wrote:

Interesting. I will have to combine with my code and put them side by
side. If I put my length and dimension into your code the result looks a
lot tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired length
keeping the balance between the norms of the cubic endpoint derivatives.
The strategy I used in the code was to change this balance in order to
reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of
an iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic
energy against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping
the two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version
with the control points equidistant below the end points.

The starting point is: bzcp=[[0, 0, 0], [0, 0, -125.85], [0, 79.721, -125.85], [0, 79.721, -108.35]]; length=180; After I adjust the control points for length I get [[0, 0, 0], [0, 0, -139.685], [0, 79.721, -139.685], [0, 79.721, -108.35]] On 26 December 2017 at 16:15, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > Would you mind to provide me the geometric data (endpoint coordinates and > strip length) of this case? > > 2017-12-26 13:32 GMT-02:00 nop head <nop.head@gmail.com>: > >> Whoops >> >> >> ​ >> >> On 26 December 2017 at 15:31, nop head <nop.head@gmail.com> wrote: >> >>> Here is my curve in red and its control points in blue alongside yours >>> with my actual geometry. Your BzEnergy function returns 12 times the energy >>> for mine which is hard to believe because mine has a more distributed >>> curvature. A strip held against the screen follows mine, not yours, so I >>> think there must be a bug in your energy function. >>> >>> On 26 December 2017 at 14:17, nop head <nop.head@gmail.com> wrote: >>> >>>> Interesting. I will have to combine with my code and put them side by >>>> side. If I put my length and dimension into your code the result looks a >>>> lot tighter and doesn't match what my real strip does. >>>> >>>> On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> >>>> wrote: >>>> >>>>> Here is the code of my atempts to find the cubic with minimum energy. >>>>> >>>>> First note that AdjustBezier() finds the cubic with the desired length >>>>> keeping the balance between the norms of the cubic endpoint derivatives. >>>>> The strategy I used in the code was to change this balance in order to >>>>> reduce the cubic energy. >>>>> >>>>> // for any cubic bz, it holds bz == balance(bz, 0.5) >>>>> function balance(bz,s) = >>>>> [ bz[0], >>>>> bz[0] + 2*s*(bz[1]-bz[0]), >>>>> bz[3] + 2*(1-s)*(bz[2]-bz[3]), >>>>> bz[3] ]; >>>>> >>>>> >>>>> For each balance, the cubic is adjusted to the target length by >>>>> AdjustBezier() and its energy is calculated. >>>>> >>>>> function BalancedEnergy(bz, s, l, eps) = >>>>> BzEnergy(AdjustBezier(balance(bz,s), l, eps)); >>>>> >>>>> >>>>> To find the balance that leads to the minimum energy is objective of >>>>> an iterative search. The search for the cubic with minimum energy is done >>>>> iteratively narrowing an interval (s1,s2) of balances that contains the >>>>> best balance. >>>>> >>>>> // Minimum energy Bezier arc with a given length l >>>>> // and given tangent directions at its ends >>>>> function BestBz(bz, l, eps=1e-3) = >>>>> let( bz2 = [ bz[0], // normalize end derivatives >>>>> bz[0]+unit(bz[1]-bz[0]), >>>>> bz[3]+unit(bz[2]-bz[3]), >>>>> bz[3] ], >>>>> s1 = eps, >>>>> en1 = BalancedEnergy(bz, s1, l, eps), >>>>> en2 = BalancedEnergy(bz, 1-s1, l, eps), >>>>> s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) >>>>> echo(smin=s) >>>>> AdjustBezier(balance(bz2,s), l); >>>>> >>>>> function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = >>>>> let( s12 = (s1+s2)/2, >>>>> e12 = BalancedEnergy(bz, s12, l, eps)) >>>>> //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) >>>>> abs(e12-(e1+e2)/2)/e12< eps ? >>>>> e1<e2 ? s1 : s2 >>>>> : >>>>> let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) >>>>> //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) >>>>> abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? >>>>> s3 >>>>> : >>>>> let( e3 = BalancedEnergy(bz, s3, l, eps) ) >>>>> //echo(e3=e3) >>>>> abs(e3-e12)/e12<eps ? >>>>> s3 : >>>>> e3<e12 ? >>>>> s3<s12 ? >>>>> _bestS(bz,l,s1,s12,e1,e12,eps,n-1) >>>>> : >>>>> _bestS(bz,l,s12,s2,e12,e2,eps,n-1) >>>>> : >>>>> s3<s12 ? >>>>> _bestS(bz,l,s3,s2,e3,e2,eps,n-1) >>>>> : >>>>> _bestS(bz,l,s1,s3,e1,e3,eps,n-1); >>>>> >>>>> >>>>> The full code is annexed. >>>>> >>>>> In the experiments I have done with the code, the plot of the cubic >>>>> energy against the balance parameter s has the shape of an U with an almost >>>>> horizontal bottom. This shows that the effect of medium-sized changes of >>>>> the optimal balance does not produce significant changes of the cubic >>>>> energy. In special, in your case of a strip going down from a fixed pole to >>>>> a moving table clamped point, the optimal balance will change slowly from >>>>> 0.5 (when the two end points are level) to 1 (when the strip is fully >>>>> stretched). That means the balance of the cubic endpoint derivatives in the >>>>> optimal solution is slightly favorable to the fixed point if the strip is >>>>> never fully stretched. So, your assumption that "keeping the two inner >>>>> control points level" would do the trick is not confirmed by my results. >>>>> >>>>> 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: >>>>> >>>>>> I don't know if this has a mathematical validity but simple keeping >>>>>> the two inner control points level with each other seems to produce a curve >>>>>> that matches a strip held against the screen fairly well. >>>>>> ​ >>>>>> The length of the strip is only 9mm longer compared to the version >>>>>> with the control points equidistant below the end points. >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> Discuss@lists.openscad.org >>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>> >>>>> >>>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
RP
Ronaldo Persiano
Tue, Dec 26, 2017 4:47 PM

You are right. The energy function was wrong. At some point, I have made
some change in it.

The correct (I hope) energy function should be:

function BzEnergy(b, n=8) =
let( bs = subdivBezier3(b, n) )
[for(i=[0:3:len(bs)-1]) pow(curvature(bs,i),2)]
*[for(i=[0:3:len(bs)-1]) 1]/pow(2,n-1);

With this function, the plot of the cubic energy as a function of the
balance s has a sharper minimum what is more reasonable.

I will try your data and compare.

2017-12-26 14:21 GMT-02:00 nop head nop.head@gmail.com:

The starting point is:

bzcp=[[0, 0, 0], [0, 0, -125.85], [0, 79.721, -125.85], [0, 79.721,
-108.35]];
length=180;

After I adjust the control points for length I get  [[0, 0, 0], [0, 0,
-139.685], [0, 79.721, -139.685], [0, 79.721, -108.35]]

On 26 December 2017 at 16:15, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Would you mind to provide me the geometric data (endpoint coordinates and
strip length) of this case?

2017-12-26 13:32 GMT-02:00 nop head nop.head@gmail.com:

Whoops

On 26 December 2017 at 15:31, nop head nop.head@gmail.com wrote:

Here is my curve in red and its control points in blue alongside yours
with my actual geometry. Your BzEnergy function returns 12 times the energy
for mine which is hard to believe because mine has a more distributed
curvature. A strip held against the screen follows mine, not yours, so I
think there must be a bug in your energy function.

On 26 December 2017 at 14:17, nop head nop.head@gmail.com wrote:

Interesting. I will have to combine with my code and put them side by
side. If I put my length and dimension into your code the result looks a
lot tighter and doesn't match what my real strip does.

On 25 December 2017 at 17:31, Ronaldo Persiano rcmpersiano@gmail.com
wrote:

Here is the code of my atempts to find the cubic with minimum energy.

First note that AdjustBezier() finds the cubic with the desired
length keeping the balance between the norms of the cubic endpoint
derivatives. The strategy I used in the code was to change this balance in
order to reduce the cubic energy.

// for any cubic bz, it holds bz == balance(bz, 0.5)
function balance(bz,s) =
[ bz[0],
bz[0] + 2s(bz[1]-bz[0]),
bz[3] + 2*(1-s)*(bz[2]-bz[3]),
bz[3] ];

For each balance, the cubic is adjusted to the target length by
AdjustBezier() and its energy is calculated.

function BalancedEnergy(bz, s, l, eps) =
BzEnergy(AdjustBezier(balance(bz,s), l, eps));

To find the balance that leads to the minimum energy is objective of
an iterative search. The search for the cubic with minimum energy is done
iteratively narrowing an interval (s1,s2) of balances that contains the
best balance.

// Minimum energy Bezier arc with a given length l
// and given tangent directions at its ends
function BestBz(bz, l, eps=1e-3) =
let( bz2 = [  bz[0], // normalize end derivatives
bz[0]+unit(bz[1]-bz[0]),
bz[3]+unit(bz[2]-bz[3]),
bz[3] ],
s1  = eps,
en1 = BalancedEnergy(bz, s1, l, eps),
en2 = BalancedEnergy(bz, 1-s1, l, eps),
s  = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) )
echo(smin=s)
AdjustBezier(balance(bz2,s), l);

function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) =
let( s12 = (s1+s2)/2,
e12 = BalancedEnergy(bz, s12, l, eps))
//echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12)
abs(e12-(e1+e2)/2)/e12< eps ?
e1<e2 ? s1 : s2
:
let( s3  = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) )
//echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n)
abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ?
s3
:
let( e3 = BalancedEnergy(bz, s3, l, eps) )
//echo(e3=e3)
abs(e3-e12)/e12<eps ?
s3 :
e3<e12 ?
s3<s12 ?
_bestS(bz,l,s1,s12,e1,e12,eps,n-1)
:
_bestS(bz,l,s12,s2,e12,e2,eps,n-1)
:
s3<s12 ?
_bestS(bz,l,s3,s2,e3,e2,eps,n-1)
:
_bestS(bz,l,s1,s3,e1,e3,eps,n-1);

The full code is annexed.

In the experiments I have done with the code, the plot of the cubic
energy against the balance parameter s has the shape of an U with an almost
horizontal bottom. This shows that the effect of medium-sized changes of
the optimal balance does not produce significant changes of the cubic
energy. In special, in your case of a strip going down from a fixed pole to
a moving table clamped point, the optimal balance will change slowly from
0.5 (when the two end points are level) to 1 (when the strip is fully
stretched). That means the balance of the cubic endpoint derivatives in the
optimal solution is slightly favorable to the fixed point if the strip is
never fully stretched. So, your assumption that "keeping the two inner
control points level" would do the trick is not confirmed by my results.

2017-12-23 10:44 GMT-02:00 nop head nop.head@gmail.com:

I don't know if this has a mathematical validity but simple keeping
the two inner control points level with each other seems to produce a curve
that matches a strip held against the screen fairly well.

The length of the strip is only 9mm longer compared to the version
with the control points equidistant below the end points.

You are right. The energy function was wrong. At some point, I have made some change in it. The correct (I hope) energy function should be: function BzEnergy(b, n=8) = let( bs = subdivBezier3(b, n) ) [for(i=[0:3:len(bs)-1]) pow(curvature(bs,i),2)] *[for(i=[0:3:len(bs)-1]) 1]/pow(2,n-1); With this function, the plot of the cubic energy as a function of the balance s has a sharper minimum what is more reasonable. I will try your data and compare. 2017-12-26 14:21 GMT-02:00 nop head <nop.head@gmail.com>: > The starting point is: > > bzcp=[[0, 0, 0], [0, 0, -125.85], [0, 79.721, -125.85], [0, 79.721, > -108.35]]; > length=180; > > After I adjust the control points for length I get [[0, 0, 0], [0, 0, > -139.685], [0, 79.721, -139.685], [0, 79.721, -108.35]] > > On 26 December 2017 at 16:15, Ronaldo Persiano <rcmpersiano@gmail.com> > wrote: > >> Would you mind to provide me the geometric data (endpoint coordinates and >> strip length) of this case? >> >> 2017-12-26 13:32 GMT-02:00 nop head <nop.head@gmail.com>: >> >>> Whoops >>> >>> >>> ​ >>> >>> On 26 December 2017 at 15:31, nop head <nop.head@gmail.com> wrote: >>> >>>> Here is my curve in red and its control points in blue alongside yours >>>> with my actual geometry. Your BzEnergy function returns 12 times the energy >>>> for mine which is hard to believe because mine has a more distributed >>>> curvature. A strip held against the screen follows mine, not yours, so I >>>> think there must be a bug in your energy function. >>>> >>>> On 26 December 2017 at 14:17, nop head <nop.head@gmail.com> wrote: >>>> >>>>> Interesting. I will have to combine with my code and put them side by >>>>> side. If I put my length and dimension into your code the result looks a >>>>> lot tighter and doesn't match what my real strip does. >>>>> >>>>> On 25 December 2017 at 17:31, Ronaldo Persiano <rcmpersiano@gmail.com> >>>>> wrote: >>>>> >>>>>> Here is the code of my atempts to find the cubic with minimum energy. >>>>>> >>>>>> First note that AdjustBezier() finds the cubic with the desired >>>>>> length keeping the balance between the norms of the cubic endpoint >>>>>> derivatives. The strategy I used in the code was to change this balance in >>>>>> order to reduce the cubic energy. >>>>>> >>>>>> // for any cubic bz, it holds bz == balance(bz, 0.5) >>>>>> function balance(bz,s) = >>>>>> [ bz[0], >>>>>> bz[0] + 2*s*(bz[1]-bz[0]), >>>>>> bz[3] + 2*(1-s)*(bz[2]-bz[3]), >>>>>> bz[3] ]; >>>>>> >>>>>> >>>>>> For each balance, the cubic is adjusted to the target length by >>>>>> AdjustBezier() and its energy is calculated. >>>>>> >>>>>> function BalancedEnergy(bz, s, l, eps) = >>>>>> BzEnergy(AdjustBezier(balance(bz,s), l, eps)); >>>>>> >>>>>> >>>>>> To find the balance that leads to the minimum energy is objective of >>>>>> an iterative search. The search for the cubic with minimum energy is done >>>>>> iteratively narrowing an interval (s1,s2) of balances that contains the >>>>>> best balance. >>>>>> >>>>>> // Minimum energy Bezier arc with a given length l >>>>>> // and given tangent directions at its ends >>>>>> function BestBz(bz, l, eps=1e-3) = >>>>>> let( bz2 = [ bz[0], // normalize end derivatives >>>>>> bz[0]+unit(bz[1]-bz[0]), >>>>>> bz[3]+unit(bz[2]-bz[3]), >>>>>> bz[3] ], >>>>>> s1 = eps, >>>>>> en1 = BalancedEnergy(bz, s1, l, eps), >>>>>> en2 = BalancedEnergy(bz, 1-s1, l, eps), >>>>>> s = _bestS(bz2, l, s1, 1-s1, en1, en2, eps) ) >>>>>> echo(smin=s) >>>>>> AdjustBezier(balance(bz2,s), l); >>>>>> >>>>>> function _bestS(bz, l, s1, s2, e1, e2, eps=1e-3, n=15) = >>>>>> let( s12 = (s1+s2)/2, >>>>>> e12 = BalancedEnergy(bz, s12, l, eps)) >>>>>> //echo("in",s1=s1,s2=s2,s12=s12,e1=e1,e2=e2,e12=e12) >>>>>> abs(e12-(e1+e2)/2)/e12< eps ? >>>>>> e1<e2 ? s1 : s2 >>>>>> : >>>>>> let( s3 = max(min(parabMin(s1,s12,s2,e1,e12,e2),1-eps),eps) ) >>>>>> //echo(s1=s1,s3=s3,s2=s2,e1=e1,e12=e12,e2=e2,n=n) >>>>>> abs(s3-s1)<eps || abs(s3-s2)<eps || n==0 ? >>>>>> s3 >>>>>> : >>>>>> let( e3 = BalancedEnergy(bz, s3, l, eps) ) >>>>>> //echo(e3=e3) >>>>>> abs(e3-e12)/e12<eps ? >>>>>> s3 : >>>>>> e3<e12 ? >>>>>> s3<s12 ? >>>>>> _bestS(bz,l,s1,s12,e1,e12,eps,n-1) >>>>>> : >>>>>> _bestS(bz,l,s12,s2,e12,e2,eps,n-1) >>>>>> : >>>>>> s3<s12 ? >>>>>> _bestS(bz,l,s3,s2,e3,e2,eps,n-1) >>>>>> : >>>>>> _bestS(bz,l,s1,s3,e1,e3,eps,n-1); >>>>>> >>>>>> >>>>>> The full code is annexed. >>>>>> >>>>>> In the experiments I have done with the code, the plot of the cubic >>>>>> energy against the balance parameter s has the shape of an U with an almost >>>>>> horizontal bottom. This shows that the effect of medium-sized changes of >>>>>> the optimal balance does not produce significant changes of the cubic >>>>>> energy. In special, in your case of a strip going down from a fixed pole to >>>>>> a moving table clamped point, the optimal balance will change slowly from >>>>>> 0.5 (when the two end points are level) to 1 (when the strip is fully >>>>>> stretched). That means the balance of the cubic endpoint derivatives in the >>>>>> optimal solution is slightly favorable to the fixed point if the strip is >>>>>> never fully stretched. So, your assumption that "keeping the two inner >>>>>> control points level" would do the trick is not confirmed by my results. >>>>>> >>>>>> 2017-12-23 10:44 GMT-02:00 nop head <nop.head@gmail.com>: >>>>>> >>>>>>> I don't know if this has a mathematical validity but simple keeping >>>>>>> the two inner control points level with each other seems to produce a curve >>>>>>> that matches a strip held against the screen fairly well. >>>>>>> ​ >>>>>>> The length of the strip is only 9mm longer compared to the version >>>>>>> with the control points equidistant below the end points. >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> OpenSCAD mailing list >>>>>> Discuss@lists.openscad.org >>>>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>>>>> >>>>>> >>>>> >>>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >>> >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >