Enter a value: 90
Original value: 90
Radian value: 1.5707963267949
Degree value: 90
Quaternion first value: 1
Quaternion first value(in degrees): 57.2957795130823
Quaternion fourth value: 6.12323399573677e-17
Quaternion fourth value(in degrees): 3.50835464926744e-15
And, just to confirm that's the correct result:
$ perl -E 'say(4*atan2(1,1) / 2)'
1.5707963267949
I suggest you run this again and check the output.
Also check that you're running exactly the same code that you posted.
"I'm using the Math::Complex module, so that might be the difference between the expected results, but I'm not sure..."
Although you've loaded the Math::Complex module, I don't see any code that uses its functionality.
In fact, if I comment out "use Math::Complex;", the output remains exactly the same.
However, even if you were using Math::Complex's constants or functions, I can't see how you'd get anything different.
Here's some fragments from its source code:
...
sub pi () { 4 * CORE::atan2(1, 1) }
...
sub cos {
my ($z) = @_ ? @_ : $_;
return CORE::cos($z) unless ref $z;
...
}
...
sub sin {
my ($z) = @_ ? @_ : $_;
return CORE::sin($z) unless ref $z;
...
}
...
And repeating the confirmation using pi from Math::Complex:
$ perl -MMath::Complex -E 'say(pi / 2)'
1.5707963267949
"I tend to not use the strict pragma because it interferes with the TK code, in that when it forces me to put quotes around certain text, the options aren't accepted by TK..."
Frankly, that's a poor reason to remove all strictures from your entire script.
If quoting right and x in
...->pack(-side=>right);
...
...->pack(-expand=>1, -fill=>x);
is really such a burden, write them like this:
...->pack(qw{-side right});
...
...->pack(qw{-expand 1 -fill x});
On the rare occasions when you really do need to turn off a stricture, turn off just one and do it the smallest scope possible. For example
use strict;
...
# all strictures on here
{
no strict 'refs';
# 'vars' and 'subs' strictures still on here
...; # <--- minimal code requiring "no strict 'refs'"
}
# all strictures on here
...
"However, warnings should definitely have been used."
I'm not certain whether you're saying they weren't used or weren't shown.
Had they been used, you would have received multiple messages like this:
$ perl -Mwarnings -E 'my @x = qw{1 2 3}; my $y = @x[1]'
Scalar value @x[1] better written as $x[1] at -e line 1.
This is what I was referring to in my previous post with: "I can see four places in your posted code where you'll not only receive a warning but also actual code to replace what you've written (e.g. "your_code" better written as "better_code")."; although, I've now spotted two more.
"Also, could you please be more specific about what you meant when you mentioned Array slices? You mentioned them, but never where in my code samples they might be used..."
Don't use slices like this (as per my previous point):
my $qx = @cam_quats[0];
my $qy = @cam_quats[1];
You didn't show how you were intending to use $qx or $qy.
If they were just for their values, you don't need them at all: you can use $cam_quats[0] and $cam_quats[1].
If, on the other hand, you wanted to modify these values without changing @cam_quats, you could have used a slice like this:
my ($qx, $qy) = @cam_quats[0,1];
However, when I originally made that point, I was thinking more about this code:
my $cam_ori1 = @cam_ori[0]; # X-orientation
my $cam_ori2 = @cam_ori[1]; # Always 0
my $cam_ori3 = @cam_ori[2]; # Always 0
my $cam_ori4 = @cam_ori[3]; # Y-orientation
# Debugging print-out
print "Orientation:\n\t$cam_ori1\n\t$cam_ori2\n\t$cam_ori3\n\t$cam
+_ori4\n\n";
# The orientation values are stored as radians, so
# calc_quatcam returns the degree equivalent, or should...
my @cam_quats = calc_quatcam($cam_ori1, $cam_ori4);
which you could've written like this using slices:
# Debugging print-out
print join("\n\t", 'Orientation:', @cam_ori[0..3]), "\n\n";
# The orientation values are stored as radians, so
# calc_quatcam returns the degree equivalent, or should...
my @cam_quats = calc_quatcam(@cam_ori[0,3]);
As you can see, you no longer need any of: $cam_ori1, $cam_ori2, $cam_ori3 or $cam_ori4. Refer back to the dot point following the one about slices.
Regarding "am more used to people knowing where my code is coming from", "Sorry about the clutter in the code samples." (and a few other related points), take a look at "I know what I mean. Why don't you?" which should address most of these.
This is only your second post so don't concern yourself too much about mistakes you've made. Mistakes are good: we all make them and, hopefully, all learn from them. :-)
|