我很抱歉,我应该知道这一点。我在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);