我很抱歉,我應該知道這一點。我在SVG 2d座標系統上有2個點。我需要獲得學位(0-360),現在我可以返回0-180回0,0-180沒有負號或正號...我可以找到密切的問題,但沒有任何結果爲0 -360。如何在SVG座標系中找到3 x/y點的旋轉度
這是在JavaScript代碼:
// center point, say 200,200
var rx = that.get("rotateOriginX"); // ember code but substitute 200,200 if you want
var ry = that.get("rotateOriginY");
// I create third point (directly up on coordinate system)
// 200, 190 - line straight up and down to angle vertex above
var p1x = rx;
var p1y = ry - 10; // this is negative 10 to go up because svg y axis starts in upper left
// mouse position variable, this can be 360 degrees around vertex
var p2x = d3.mouse(this.parentNode.parentNode)[0];
var p2y = d3.mouse(this.parentNode.parentNode)[1];
// I have three points now
var p0c = Math.sqrt(Math.pow(rx-p1x, 2) + Math.pow(ry-p1y, 2));
var p1c = Math.sqrt(Math.pow(rx-p2x, 2) + Math.pow(ry-p2y, 2));
var p0p1 = Math.sqrt(Math.pow(p2x-p1x, 2) + Math.pow(p2y-p1y, 2));
// this always returns 0-180-0 but is not signed (+/-)
// ALL I WANT IS 0-360 so I can rotate a shape to user's preference as determined by mouse
var degrees = (180 * (Math.acos((p1c*p1c+p0c*p0c-p0p1*p0p1)/(2*p1c*p0c)))/Math.PI);