javascript - Rotated line is offset -
i've been trying rotate line originates @ center of circle towards cursor in javascript. have moving offset actual direction. there reason this? i'd rather not have add direction until syncs up.
this how direction:
var deltay = pointery - chary; var deltax = pointerx - chary; chardirection = math.atan2(deltay,deltax) * 180/ math.pi;
and how i'm calculating new point want 100 points away center.
var directioninradians = chardirection * (math.pi/180); var newx = 100 * math.cos(directioninradians) - 100 * math.sin(directioninradians); var newy = 100 * math.cos(directioninradians) + 100 * math.sin(directioninradians);
i not sure why perform newx/y calculation way do. proper calculation lot simpler:
var newx = 100 * math.cos(directioninradians); var newy = 100 * math.sin(directioninradians);
demo.
Comments
Post a Comment