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); 

jsfiddle post

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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -