围绕任意轴旋转的通知 [英] Circular rotation around an arbitrary axis

查看:131
本文介绍了围绕任意轴旋转的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程星际争霸2自定义地图,并得到了一些proglems与数学在3D。目前,我想创建和绕任意轴的点,X,Y和Z(XYZ的向量进行归一化)。

I am programming Starcraft 2 custom maps and got some proglems with math in 3D. Currently I am trying to create and rotate a point around an arbitrary axis, given by x,y and z (the xyz vector is normalized).

我一直在试图围绕了很多,阅读互联网上的很多东西,但我只是无法得到它的工作原理正确。我现在的脚本(你可能不知道的语言,但它没有什么特别的)是打破一切几个小时的结果(不正常):

I've been trying around a lot and read through a lot of stuff on the internet, but I just cant get how it works correctly. My current script (you probably dont know the language, but it's nothing special) is the result of breaking everything for hours (doesn't work correctly):

    point CP;
fixed AXY;
point D;
point DnoZ;
point DXY_Z;
fixed AZ;
fixed LXY;
missile[Missile].Angle = (missile[Missile].Angle + missile[Missile].Acceleration) % 360.0;
missile[Missile].Acceleration += missile[Missile].AirResistance;
if (missile[Missile].Parent > -1) {
    D = missile[missile[Missile].Parent].Direction;
    DnoZ = Point(PointGetX(D),0.0);
    DXY_Z = Normalize(Point(SquareRoot(PointDot(DnoZ,DnoZ)),PointGetHeight(D)));
    AZ = MaxF(ACos(PointGetX(DXY_Z)),ASin(PointGetY(DXY_Z)))+missile[Missile].Angle;
    DnoZ = Normalize(DnoZ);
    AXY = MaxF(ACos(PointGetX(DnoZ)),ASin(PointGetY(DnoZ)));
    CP = Point(Cos(AXY+90),Sin(AXY+90));
    LXY = SquareRoot(PointDot(CP,CP));
    if (LXY > 0) {
        CP = PointMult(CP,Cos(AZ)/LXY);
        PointSetHeight(CP,Sin(AZ));
    } else {
        CP = Point3(0.0,0.0,1.0);
    }
} else {
    CP = Point(Cos(missile[Missile].Angle),Sin(missile[Missile].Angle));
}
missile[Missile].Direction = Normalize(CP);
missile[Missile].Position = PointAdd(missile[Missile].Position,PointMult(missile[Missile].Direction,missile[Missile].Distance));

我不能让我的脑海里围绕数学。如果你能在简单的术语解释,这将是最好的解决办法,一个code剪断将是一件好事,以及(但不太有帮助,因为我打算做更多的3D的东西,在未来的)。

I just cant get my mind around the math. If you can explain it in simple terms that would be the best solution, a code snipped would be good as well (but not quite as helpful, because I plan to do more 3D stuff in the future).

推荐答案

<一个href="http://en.wikipedia.org/wiki/Rotation_matrix">http://en.wikipedia.org/wiki/Rotation_matrix.你看,从轴和角度部分旋转矩阵下。为了您的方便,在这里您需要的矩阵。这是一个有点毛。 THETA的角度,UX,UY,和UZ是在x,y和z的分量在轴矢量

http://en.wikipedia.org/wiki/Rotation_matrix. Look under the section Rotation matrix from axis and angle. For your convenience, here's the matrix you need. It's a bit hairy. theta is the angle, and ux, uy, and uz are the x, y, and z components of the normalized axis vector

如果你不理解矩阵和向量,回来后,我会帮你。

If you don't understand matrices and vectors, post back and I'll help you.

这篇关于围绕任意轴旋转的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆