2

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:

sra
  • 717
  • 4
  • 15
  • Your code doesn't run as shown. For instance, your first variable angle should probably be called angles, as you show in use further down when you define p1. Further, the SplineFit doesn't work because i is not defined. Please past back the code you post in a clean mathematica session and make the necessary modifications until it runs. – MarcoB Jun 18 '15 at 19:17
  • @MarcoB Thanks. It was written to analyze multiple polymers.I forgot to clean those stuffs in this code. Now, it should run fine. – sra Jun 18 '15 at 19:49

1 Answers1

2

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}
*)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Note : This is still doesn't give ordered/sorted coordinates. As discussed here: http://mathematica.stackexchange.com/questions/86382/confusion-with-splinefit-angle-calculation – sra Jun 19 '15 at 17:29