How to find 2 data point in Bezier satisfy the condition the Chord Length Method?

180 Views Asked by At

enter image description hereSuppose bezier curve have 4 control point $P0$, $P1$, $P2$, $P3$. How to find 2 data point $D1$, $D2$ satisfy the condition the Chord Length Method? The Chord Length Method :

 L = |D1-D0| + |D2-D1| +|D3-D2| =  d1 + d2 + d3;
 t1 = |D1-D0| / L = d1 /L
 t2 = |D1-D0| + |D2-D1| / L = (d1+d2)/L

where Di is data point. $D1 = C(t1)$; $D2 = C(t2)$ ; $D0=P1$ ; $D3=P3$ and $t0=0$, $t3 =1$

i have write program but can not solve.Please help me.

p0 = {0, 0};
p1 = {1, 1};
p2 = {2, 0};
p3 = {3, 2};

pts = {p0, p1, p2, p3};
f = BezierFunction[pts];
f1[t1_, t2_] = EuclideanDistance  [f[t1], 
p0] /(EuclideanDistance  [f[t1], p0] +  EuclideanDistance  [f[t2], 
   f[t1]] +   EuclideanDistance  [f[t2], p3]);
  f1[t1_, t2_] = (EuclideanDistance  [f[t1], p0] + 
  EuclideanDistance  [f[t2], f[t1]] )/(EuclideanDistance  [f[t1], p0] + 
       EuclideanDistance  [f[t2], f[t1]] +   
        EuclideanDistance  [f[t2], p3]);
FindRoot[ {f1[t1, t2] ==  t1, f2[t1, t2] ==  t2}, {{t1, 0}, {t2, 0}}]

or

NSolve[{f1[t1, t2] ==  t1, f2[t1, t2] ==  t2}, {{t1, 0}, {t2, 0}}]
3

There are 3 best solutions below

0
On

Thansk for read.The chord length method is method of interpolating B-Spline curve. This is referent http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/INT-APP/PARA-chord-length.html

i rewrite mycode

p0 = {0, 0};
p1 = {1, 1};
p2 = {2, 0};
p3 = {3, 2};
p = {p0, p1, p2, p3};

f[t_] = (1 - t)^3*p[[1]] + 3*(1 - t)^2 * t *p[[2]]  + 
  3*(1 - t) t^2*p[[3]] + t^3*p[[4]]  ;
g1[t1_, t2_]  = 
 EuclideanDistance[f[t1], p[[1]] ]/ ( 
   EuclideanDistance[f[t1], p[[1]] ] + 
    EuclideanDistance[f[t2], f[t1]] + 
    EuclideanDistance[f[t2], p[[4]] ]);
g2[t1_, t2_]  = (EuclideanDistance[f[t1], p[[1]] ] + 
    EuclideanDistance[f[t2], f[t1]])/ ( 
   EuclideanDistance[f[t1], p[[1]] ] + 
    EuclideanDistance[f[t2], f[t1]] + 
    EuclideanDistance[f[t2], p[[4]] ]);
sol = NSolve[ {g1[t1, t2] == t1, t1 > 0, t1 < 1, g2[t1, t2] == t2, 
   t2 > 0, t2 < 1, t2 > t1}, {t1, t2}];

Program find 2 roots but very slowly.How to convert NSolve to FindRoot ?

0
On

I'm still not really sure what is given in this problem and what you are trying to calculate.

It sounds like you are given a curve, with control points $P_0$, $P_1$, $P_2$, $P_3$, and you know it was constructed by interpolating two (unknown) points $D_1$ and $D_2$, using chord-length parameterization, and you want to find the corresponding parameter values $t_1$ and $t_2$. Is that correct? It seems like a strange problem.

Your code would be much easier to read (and faster) if you wrote:

r1 = EuclideanDistance[ p[1],  f[t1] ]
r2 = EuclideanDistance[ f[t1], f[t2] ]
r3 = EuclideanDistance[ f[t2], p[4]  ]
g1[t1,t2] = r1/(r1+r2+r3)
g2[t1,t2] = (r1 + r2)/(r1+r2+r3)

The two equations you are solving involve complicated functions of $t_1$ and $t_2$ with many square roots. So, you will almost certainly need to use numerical methods to solve them.

You don't say what programming language you are using, but it looks like Mathematica. No matter what it is, the numerical methods will converge much more quickly if you give them good starting points. You could use $t_1 = 1/3$ and $t_2 = 2/3$, for example, or something based on distances between the points $P_0$, $P_1$, $P_2$, $P_3$. Any decent starting point is better than nothing.

You should use the Mathematica function FindRoot, which allows you to provide guessed values near the desired roots. The function NSolve only works with polynomials, and it doesn't allow you to provide a guess.

0
On

Yes,it is mathematics's code. I writed code :

p0 = {0, 0};
p1 = {28.1, 35.6};
p2 = {84, 60.1};
p3 = {125, 36};
p = {p0, p1, p2, p3};
f[t_] = (1 - t)^3*p[[1]] + 3*(1 - t)^2 * t *p[[2]]  + 
   3*(1 - t) t^2*p[[3]] + t^3*p[[4]]  ;
d1 = EuclideanDistance[f[t1], p[[1]] ];
d2 = EuclideanDistance[f[t2], f[t1]];
d3 = EuclideanDistance[f[t2], p[[4]] ];
l = d1 + d2 + d3;
g1[t1_, t2_]  = d1 / l;
g2[t1_, t2_]  = (d1 + d2)/ l;
sol = NSolve[ 
   Rationalize[{g1[t1, t2] == t1, t1 > 0, t1 < 1, g2[t1, t2] == t2, 
     t2 > 0, t2 < 1, t2 > t1}], {t1, t2}, 4];

When this program run about 15 minuts,Mathematics can not solve system.

I writed code :

p0 = {0, 0};
p1 = {28, 35};
p2 = {84, 60};
p3 = {125, 36};
p = {p0, p1, p2, p3};
f[t_] = (1 - t)^3*p[[1]] + 3*(1 - t)^2 * t *p[[2]]  + 
   3*(1 - t) t^2*p[[3]] + t^3*p[[4]]  ;
g1[t1_, t2_]  = 
  EuclideanDistance[f[t1], p[[1]] ]/ ( 
    EuclideanDistance[f[t1], p[[1]] ] + 
     EuclideanDistance[f[t2], f[t1]] + 
     EuclideanDistance[f[t2], p[[4]] ]);
g2[t1_, t2_]  = (EuclideanDistance[f[t1], p[[1]] ] + 
     EuclideanDistance[f[t2], f[t1]])/ ( 
    EuclideanDistance[f[t1], p[[1]] ] + 
     EuclideanDistance[f[t2], f[t1]] + 
     EuclideanDistance[f[t2], p[[4]] ]);
NSolve[ Rationalize[{g1[t1, t2] == t1, t1 > 0, t1 < 1, 
   g2[t1, t2] == t2, t2 > 0, t2 < 1, t2 > t1}], {t1, t2}, 4]

Mathematics solve this system about 5 seconds : [Out] {{t1 -> 0.1278, t2 -> 0.8057}, {t1 -> 0.7281, t2 -> 0.7892}}

i change p2{84, 60} to p2 = {82, 60},system no root.What is a wrong ?

p0 = {0, 0};
p1 = {28, 35};
p2 = {82, 60};
p3 = {125, 36};
p = {p0, p1, p2, p3};
f[t_] = (1 - t)^3*p[[1]] + 3*(1 - t)^2 * t *p[[2]]  + 
   3*(1 - t) t^2*p[[3]] + t^3*p[[4]]  ;
d1 = EuclideanDistance[f[t1], p[[1]] ];
d2 = EuclideanDistance[f[t2], f[t1]];
d3 = EuclideanDistance[f[t2], p[[4]] ];
l = d1 + d2 + d3;
g1[t1_, t2_]  = d1 / l;
g2[t1_, t2_]  = (d1 + d2)/ l;
sol = NSolve[ 
   Rationalize[{g1[t1, t2] == t1, t1 > 0, t1 < 1, g2[t1, t2] == t2, 
     t2 > 0, t2 < 1, t2 > t1}], {t1, t2}, 4];
[Out] {}

You writed "You could use t1=1/3 and t2=2/3, for example, or something based on distances between the points P0, P1, P2, P3. Any decent starting point is better than nothing." I dont know How to set starting point t1=1/3 and t2=2/3 in Mathematica when use NSolve.