javascript - How to convert a point to polar coordinates in ECMAScript? -
javascript - How to convert a point to polar coordinates in ECMAScript? -
i need turn click location polar coordinate. current algorithm. location location on canvas of click ({x:evt.clientx, y:evt.clienty}
), center offset of origin 0,0. example, if circle centered on 250, 250, center {x:250, y:250}
. scale scale of radius. example, if radius of circle center 50 , scale .5, radius becomes 25. (it's zooming in/out)
this.getpolarlocation = function(location){ var unscaledfromcenter = { x: location.x - center.x, y: location.y - center.y }; var angle = this.getangleoncircle(unscaledfromcenter); var dist = math.sqrt(unscaledfromcenter.x * unscaledfromcenter.x + unscaledfromcenter.y * unscaledfromcenter.y) * this.ds.scale; homecoming { angle:angle, dist:dist, tostring: function(){ homecoming "theta: ".concat(angle).concat("; dist: ").concat(dist); } }; } this.getangleoncircle = function(location){ var x = location.x; var y = location.y; if(x == 0 && y > 0) homecoming math.pi / 2; if(x == 0 && y < 0) homecoming 3 * math.pi / 2; if(y == 0 && x > 0) homecoming 0; if(y == 0 && x < 0) homecoming math.pi; var angle = math.atan(y/x); if(x > 0 && y > 0) homecoming angle; if(x < 0) homecoming math.pi + angle homecoming math.pi * 2 + angle; }
screenshots of issue. left happens zoomed out (and not supposed happen). right zoomed in (scale >= 1), , supposed happen.
i'm under impression center coordinates beingness shifted off. seems work fine scale >= 1, not scale < 1
source: circos.html: http://pastie.org/private/cowsjz7mcihy8wtv4u4ag circos.js: http://pastie.org/private/o9w3dwccmimalez9fropa datasource.js: http://pastie.org/private/iko9bqq8eztbfh8xpvnoaw run in firefox
so question is: why doesn't work?
for reason, programme automagically works when close firebug. doesn't seem work on firefox 5, version have (in 3s somewhere). either way, i'm scrapping project more object oriented. there's no way current algorithm handle genome. (which i'm going mapping)
update:
i figured out problem... measuring distance top left of page, not top left of canvas. thus, when firebug enabled, screen shifted, making problems worse. solution utilize canvas.offsetleft , canvas.offsettop calculate position on canvas.
javascript coordinates trigonometry
Comments
Post a Comment