求计算三角形夹角的Laya代码

已知A,B,C三个点,求AC边和AB边的夹角度。
未标题-4.jpg
已邀请:

155*****727

赞同来自:

var a1,a2,a3;
var b1,b2,b3;
var c1,c2,c3;
var A;//点A
var B;//点B
var C;//点C
var BA;//向量BA
var CA;//向量CA
var cosA;//角A余弦
var jA;//角A
A=new Laya.Vector3(a1,a2,a3);
B=new Laya.Vector3(b1,b2,b3);
C=new Laya.Vector3(c1,c2,c3);
BA=new Laya.Vector3(a1-b1,a2-b2,a3-b3);
CA=new Laya.Vector3(a1-c1,a2-c2,a3-c3);
cosA= ((a1-b1)*(a1-c1)+(a2-b2)*(a2-c2)+(a3-b3)*(a3-c3))/(Math.sqrt((a1-c1)*(a1-c1)+(a2-c2)*(a2-c2)+(a3-c3)*(a3-c3))*Math.sqrt((a1-b1)*(a1-b1)+(a2-b2)*(a2-b2)+(a3-b3)*(a3-b3)))
jA=Math.acos(cosA);

魔狼

赞同来自:

// a为A点
Calculate(a:Laya.Vector3, b:Laya.Vector3, c:Laya.Vector3)
{
    let d_a:number = Laya.Vector3. distance(b, c);   
    let d_b:number = Laya.Vector3. distance(a, c);
    let d_c:number = Laya.Vector3.distance(a, b);  
    //angleA表示A点的夹角
    let angleA = Math.acos((d_b * d_b + d_c * d_c - d_a * d_a) / (2 * d_b * d_c)) * 180 / Math.PI ;
    let angleB = Math.acos((d_a * d_a + d_c * d_c - d_b * d_b) / (2 * d_a * d_c)) * 180 / Math.PI ; 
    let angleC = Math.acos((d_a * d_a + d_b * d_b - d_c * d_c) / (2 * d_a * d_b)) * 180 / Math.PI ;
    console.log(angleA + " " + angleB + " " + angleC);
}

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作