Michael,
Tried your suggestion for clockwise/counterclockwise, but it doesn't work because I need to know clockwise or counterclockwise from the direction of travel, not relative to absolute cartesian space.
code:
// DOESNT WORK
function isClockwise(k,l,m)
{
var XLK = l.x - k.x;
var XMK = m.x - k.x;
var YLK = m.y - k.y;
var YMK = m.y - k.y;
signed_area = 0.5 * (( XLK*YMK ) - ( XMK*YLK ));
if( signed_area > 0)
return 1;
else if( signed_area < 0)
return -1;
else
return 0;
}
var min = segment.domainMin;
var max = segment.domainMax;
var len = max - min;
var start = segment.getStartPt();
var midpoint = segment.evaluatePoint( min + (0.5 * len) );
var end = segment.getEndPt();
var clockwise = isClockwise( start, midpoint, end );
This below works for any arcs that are not 180 deg, but 180 degree arcs resolve to an arc angle of pi, so it doesnt know which direction to turn:
code:
// WORKS FOR ANY ARC THAT IS NOT 180 degrees (pi radians).
function isClockwise( p0,p1,c )
{
var pi = Math.PI;
var angle = Math.atan2(p0.y - c.y, p0.x - c.x) - Math.atan2(p1.y - c.y, p1.x - c.x);
if ( angle == 0 || angle == pi )
return 0;
else if ( angle > 0 && angle < pi )
return 1;
else if ( angle> pi )
return -1;
else if ( angle < 0 && angle> (pi * -1))
return -1;
else if ( angle < (pi * -1))
return 1;
}
var clockwise = isClockwise( segment.getStartPt(),segment.getEndPt(), segment.conicFrame.origin );
>Len
|