我有四点喜欢
P1A (10,9)
P1B (10,10)
P2A (11,10)
P2B (11,9)
这显示了
LineA(从P1A ~ P2A)
和LineB(从P1B ~ P2B)
现在,我想得到两条线的 Angular 。
在这种情况下, Angular 必须为 90 度。
如何通过编程获取 Angular ?
如果我能在 php 或 javascript 上得到这个想法,我很高兴
我认为向量 a,b 的公式一定是这样的。
cosθ = a1 x b1 + a2 x b2/MathSqrt(a1 x a1 + a2 x a2) x MathSqrt(b1 x b1 + b2 x b2)
但是我怎样才能将P1A,P1B,P2A,P2B代入这个公式?
最佳答案
在 JavaScript 中你可以使用 Math.atan2()
The Math.atan2() method returns a numeric value between -π and π representing the angle theta of an (x, y) point.
let P1A = {
x: 10,
y: 9
};
let P1B = {
x: 11,
y: 10
};
// angle in radians
let angleRadians = Math.atan2(P1B.y - P1A.y, P1B.x - P1A.x);
// angle in degrees
let angleDeg = Math.atan2(P1B.y - P1A.y, P1B.x - P1A.x) * 180 / Math.PI;
关于javascript - 如何求两条交叉线的夹 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49425796/