Matej Posted May 17, 2015 Share Posted May 17, 2015 Yo , im building time picked with javascript and i found interessting problem , demo = http://jsfiddle.net/afo7ky03/6/ whenever you move rotating div between 2 and 3 it stops there and it shouldnt happen , i havent found any problem in scripts , did i overlooked something? thanks for answers Link to comment Share on other sites More sharing options...
Hadien Posted May 18, 2015 Share Posted May 18, 2015 its "simple" math really, run a google search on "graph arctan2" and choose images, you should see what going on from that. basically when the y input into Math.arctan2() approaches 0 the number becomes undefined and returns a NAN. use ArcSin instead. you'll need the X delta (which you already have and pathagorean therom to find the distance (the hypotenuse or magnitude) which the mouse is from the origin. then... Math.arcsin(deltaX/magnitude); you'll never want to use arctan (DeltaX/DeltaY) in this case as you'll have the risk of DeltaY nearing zero and giving you a div/0 error Link to comment Share on other sites More sharing options...
Matej Posted May 18, 2015 Author Share Posted May 18, 2015 What is the magnitude in this case? deltaX would be g-raduzs (defined in fiddle) , and magnitude should be new position of X? a.k.a Asin(g-radius/new_client) cuz thats what i tried as first but seems like isnt working properly //sorry im not familiar with names of math expressions in english and translators are pain in this case :/ Link to comment Share on other sites More sharing options...
Hadien Posted May 18, 2015 Share Posted May 18, 2015 (edited) var rect = one.getBoundingClientRect();var DeltaX = e.offsetX - (rect.left+rect.width/2);var DeltaY = e.offsety - (rect.top+rect.height/2);var Magnitude = (DeltaX^2 + DeltaY^2)^Delta^0.5;//should provide a degree range of -89 to 270var degree = (DeltaY>0)?Math.arcsin(DeltaX/Magnitude) :180 - Math.arcsin(DeltaX/Magnitude); When I have some time I'll come back and provide some polished code, but now I have some work to do. hopefully you can use what I gave you. EDIT: So here is the fully updated code after I had the time to actually sit down and work with it http://jsfiddle.net/afo7ky03/21/ Edited May 19, 2015 by Hadien Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now