Skip to main content

bugs - RegionMeasure is wrong for simple 1D Path


Bug introduced in 11.1




Take the simple path defined by a line through a set of points


pts = {{0, 0}, {0, 1.5}, {0.05, 1.5}, {0.05, 0.5}, {0.1, 0.5}, {0.1,  1.5},
{0.15, 1.5}, {0.15, 0.5}, {0.2, 0.5}, {0.2, 1.5}, {0.25, 1.5}, {0.25, 0.5},
{0.3, 0.5}, {0.3, 1.5}, {0.35, 1.5}, {0.35, 0}}


reg = Line[pts];

This can be visualized using Graphics


Graphics[{Blue, reg}, Axes -> True]

image


Both RegionMeasure and ArcLength should give us the length of the line and in fact it does give us a number


RegionMeasure@reg
(* 7.85 *)

ArcLength@reg
(* 7.85 *)

This is wrong however!


This gives the sequence of the individual arc lengths:


FoldPairList[{Abs@Total[#2 - #1], #2} &, {0, 0}, pts]
(* {0., 1.5, 0.05, 1., 0.05, 1., 0.05, 1., 0.05, 1., 0.05, 1., 0.05, 1., 0.05, 1.5} *)

The sum of this sequence is $9.35$ not $7.85$.


Sanity check: Count the line segments on screen. There are two segments of length $1.5$, seven segments of length $0.05$, and six segments of length $1$. So in total: $2\times1.5 + 7\times0.05 + 6\times1 = 9.35$





I use Mathematica 11.1.1.0 on Mac OS 10.12.6




Edit in response to comments:


When I copy and paste pts from SE I also get $9.35$. Try the following which I used to generate pts in the first place:


pts2 = AnglePath[{{1.5, 90.°}, {0.05, -90.°}, {1, -90.°}, {0.05, 90.°}, {1, 90.°},
{0.05, -90.°}, {1, -90.°},{0.05, 90.°}, {1, 90.°}, {0.05, -90.°}, {1, -90.°},
{0.05, 90.°}, {1, 90.°}, {0.05, -90.°}, {1.5, -90.°}}] //Chop

and check that pts and pts2 are in fact equal



pts == pts2
(* True *)

Now try RegionMeasure@Line@pts2. For me this gives $7.85$. Seems the culprit is AnglePath.




Comments