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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -