如何使用 XYZ 角度创建 3D 矢量

时间:2021-06-23 13:34:18

标签: math vector lua trigonometry

所以我发现了如何仅使用一个角度在 2D 中创建 vector2,但现在我需要使用两个或三个角度的 vector3

我用来获取二维向量的代码:

function V2ToForce(Angle,Force)
    local Force = Force or 1
    local X,Y = math.cos(Angle)*Force,math.sin(Angle)*Force 
    return X,Y
end

任何伪代码都会有所帮助。

编辑: 我找到了这个公式,但也不起作用

function Test(X,Y,Force)    
    local x = math.cos(X) * math.cos(Y);    
    local z = math.sin(X) * math.cos(Y);    
    local y = math.sin(Y);  
    return x*Force,y*Force,z*Force 
end

1 个答案:

答案 0 :(得分:0)

评论的人让它工作了,仍然有一些错误,但没有什么是 if 语句无法解决的。

这就是我遇到同样问题的人的结果

function Test1(X,Y,Force)
    local X1 = math.cos(Y)*Force
    local Y1 = (math.sin(Y)*math.sin(X))*Force
    local Z1 = (-math.sin(Y)*math.cos(X))*Force
    return X1,Y1,Z1
end
function Test2(X,Y,Force)
    local X1 = math.cos(X) * math.cos(Y)
    local Z1 = -math.sin(X) * math.cos(Y)
    local Y1 = math.sin(Y)
    return X*Force,Y*Force,Z1*Force 
end

抱歉我的英语不好

相关问题