【发布时间】:2014-09-29 01:02:22
【问题描述】:
我正在尝试围绕它的中点旋转一个三角形...计算中点并以这种格式存储在一个数组中:
中点 = [midpointX,midpointY];
点的存储方式与 points.a = [x,y] 和 points.b 和 points.b 等的存储方式相同...
这是我用于旋转点 A 的公式例如,由于某种原因返回的值是 null? (附注:rotationAngle 以度为单位)
新 X = (midpoint[0] + (points.a[0]-midpoint[0])*Math.cos(Math.PI*(trig.rotation)/180) - (points.a[1]-midpoint[1])*Math.sin(Math.PI*(trig.rotation)/180))
新 Y = (midpoint[1] + (points.a[1]-midpoint[1])*Math.cos(Math.PI*(rotationAngle)/180) + (points.a[0]-midpoint[0])*Math.sin(Math.PI*(rotationAngle)/180))
编辑:忘了说这是在 ng-attr 中
【问题讨论】:
-
@gandaliter 抱歉忘记了代码标签
-
奇怪。除非计算中使用的值之一为 null,否则它不应返回 null,并且
Math.sin和Math.cos不能返回 null。您可以尝试将计算与中间变量分开并在每一行测试 null,以查看问题出在哪里。 -
中点指的是centroid?还是midpoint therom?
标签: javascript math svg rotation trigonometry