I am creating a polymer(where each monomer is of equal length) using this method:
angles = RandomVariate[NormalDistribution[0, 0.2], 40];
a1 = 1;
anglePath1[angles_, a_] := FoldList[# + a {Cos@#2, Sin@#2} &, {0, 0}, Accumulate@angles]
p1 = anglePath1[angles, a1];
Then, I use SplineFit
Needs["Splines`"];
spt = SplineFit[p1, Cubic];
lt = spt[[2, -1]];
Then, I break the polymer into monomer of equal length. To do so, I calculate the arc length of the polymer:
dz = .0000001;
arc = NIntegrate[Norm[(spt[z + dz] - spt[z])/dz], {z, 0, lt}]
mesh = Solve [arc/a1 == div];
meshf = Round[div /. mesh];
After this I extract co-ordinates:
plot = ParametricPlot[spt[t], {t, 0, lt},
MeshFunctions -> {"ArcLength"}, Mesh -> {meshf[[1]]},
MeshStyle -> {PointSize[0.01], Red}]
coord = Cases[Normal@plot, Point[p_] :> p, Infinity];
So, now I calculate distance between each points:
(*distance calculated using initially created co-ordinates*)
Norm /@ Differences@p1
(*distance calculated using co-ordinates grabbed from spline fitted curve*)
Norm /@ Differences@coord
These two distances are different and I don't understand why.
The method calculating arc length and grabbing co-ordinates are from @MichaelE2 answer from this post:
Answer
Your points aren't in order. Change:
coord = Cases[Normal@plot, Point[p_] :> p, Infinity]
by
coord = Sort@Cases[Normal@plot, Point[p_] :> p, Infinity]
Then you'll get
(Norm /@ Differences@p1)[[1 ;; 5]]
(Norm /@ Differences@coord)[[1 ;; 5]]
(*
{1., 1., 1., 1., 1.}
{0.976258, 0.97659, 0.975463, 0.976125, 0.976947}
*)
Comments
Post a Comment