2
我用网络中的C++示例编写了这段代码,以旋转3D中的一组点。修复旋转3D对象Perl代码
#@matrix is points and their 3D coordinates.
@rotated_matrix = rotate_l(\@matrix, 0);
sub rotate_l {
my $ref = $_[0];
my $x = 0;
my $step = 1;
#if rotx
if ($_[1] == 0) {
while ($$ref[$x][0]) {
$$ref[$x][1] += ($$ref[$x][1]*cos($step) - $$ref[$x][2]*sin($step));
$$ref[$x][2] += ($$ref[$x][1]*sin($step) + $$ref[$x][2]*cos($step));
$x++;
}
}
#if roty
if ($_[1] == 1) {
while ($$ref[$x][0]) {
$$ref[$x][0] += ($$ref[$x][0]*cos($step) + $$ref[$x][2]*sin($step));
$$ref[$x][2] += (-$$ref[$x][0]*sin($step) + $$ref[$x][2]*cos($step));
$x++;
}
}
#if rotz
if ($_[1] == 2) {
while ($$ref[$x][0]) {
$$ref[$x][0] += ($$ref[$x][0]*cos($step) - $$ref[$x][1]*sin($step));
$$ref[$x][1] += ($$ref[$x][0]*sin($step) + $$ref[$x][1]*cos($step));
$x++;
}
}
return @$ref;
}
但是有什么不对。对象大小/形式不能保持不变。我的数学不是很好理解为什么。我甚至不确定我需要+=
或=
?
C++示例是否工作? – choroba
我强烈怀疑'$ step'要乘以'2 pi',并且所有'+ ='都将被替换为'='。然后它几乎奏效。 – amon
我发誓,花了一分多时间才意识到这个页面上有Perl代码。我正要在一个评论中提问:“这个问题与Perl有什么关系?你想把这个C++翻译成Perl吗?你试过了什么?” –