0

two.js library has a function as follows;

makeArcSegment two.makeArcSegment(ox, oy, ir, or, sa, ea, res);

I calculate my parameters as follows;

var prevPt = points[i - 1];

var dxNext = nextPt.x - pt.x;
var dyNext = nextPt.y - pt.y;
var angleNext = Math.atan2(dyNext, dxNext);

var dxPrev = prevPt.x - pt.x;
var dyPrev = prevPt.y - pt.y;
var anglePrev = Math.atan2(dyPrev, dxPrev);

var innerRadius = 0;
var outerRadius = 20;

var arc = two.makeArcSegment(pt.x, pt.y, innerRadius, outerRadius, anglePrev, angleNext)

And my output is kind of unexpected.

enter image description here

At first node (after the line with the length of 225.46), sweep direction is counter clockwise. At second node (after 142.35), sweep direction is clockwise.How do I force it to be always counter clockwise?

Thanks.

2 Answers2

0

According to this if you make the arc.endAngle less than the arc.startAngle then it should go in the opposite direction..

So you can try to draw between min(prev,next) and max(prev,next) as workaround.

Also make all angles positive (adding 2*Pi to negative ones).

Looks like serious flaw of library though.

MBo
  • 77,366
  • 5
  • 53
  • 86
0

This is the workaround I found.

      if (anglePrev < 0.0)
      {
          anglePrev += Math.PI * 2.0;
      }
      if (angleNext < 0.0)
      {
          angleNext += Math.PI * 2.0;
      }
      if (angleNext > anglePrev)
      {
          anglePrev += Math.PI * 2.0;
      }