且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

围绕其中心/轴旋转 3D 形状

更新时间:2023-02-01 20:05:27

上面的代码绕原点旋转.如果您的旋转中心(例如 $c)不是原点,您可以在旋转前移动对象:

The code above rotates about the origin. If your centre of rotation (say, $c), isn't the origin, you can move the object before rotating:

$px = $vertex->x - $c->x;
$py = $vertex->y - $c->y;
$pz = $vertex->z - $c->z;

旋转后,将点移回旋转中心:

After rotating, move the point back to the centre of rotation:

$points = 
[
    'x' => ($Axx * $px + $Axy * $py + $Axz * $pz) + $c->x, 
    'y' => ($Ayx * $px + $Ayy * $py + $Ayz * $pz) + $c->y, 
    'z' => ($Azx * $px + $Azy * $py + $Azz * $pz) + $c->z
];