Diab Jerius
2014-02-03 19:42:39 UTC
[Please pardon the possible duplicate message]
Over at stackoverflow there's a question on rotating a 2D matrix:
https://stackoverflow.com/questions/21433364/use-perl-pdl-to-rotate-a-matrix
(Please add your own favorite solution.)
One solution that's custom built would seem to be rot2d. a 90 degree
rotation (with anti-aliasing turned off for good measure) should
provide an exact result.
In any case, here's what I got:
pdl> p $m = pdl( [ 1..3],[4..6],[7..9])
[
[1 2 3]
[4 5 6]
[7 8 9]
]
pdl> p $m->rot2d( 90, 0, 1 )
[
[0 0 0]
[3 6 9]
[2 5 8]
]
Looks good. Except for those pesky 0's. Where'd they come from? It
looks like it's rotating about the "6", not the "5", and filling in
the off-matrix values with my specified value of 0.
I'm tempted to call this an off-by-one error in the x direction, but
then I gave rot2d a nice even-sized matrix:
pdl> p $m = pdl( [ 1..4],[5..8],[9..12],[13..16])
[
[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]
[13 14 15 16]
]
pdl> p $m->rot2d( 90, 0, 1 )
[
[ 0 0 0 0]
[ 4 8 12 16]
[ 3 7 11 15]
[ 2 6 10 14]
]
with the same results. The x coord of the rotation center is
off-by-one from what I would consider the rotation center. Typically
such errors resolve themselves when switching from even to odd sizes,
so now I wonder if this is a feature rather than a bug.
There's a hard-coded 0.999999 in the code which gives me the willies,
but I haven't dissected it to figure out why it has the above
properties.
Any thoughts? Bug? Feature?
Over at stackoverflow there's a question on rotating a 2D matrix:
https://stackoverflow.com/questions/21433364/use-perl-pdl-to-rotate-a-matrix
(Please add your own favorite solution.)
One solution that's custom built would seem to be rot2d. a 90 degree
rotation (with anti-aliasing turned off for good measure) should
provide an exact result.
In any case, here's what I got:
pdl> p $m = pdl( [ 1..3],[4..6],[7..9])
[
[1 2 3]
[4 5 6]
[7 8 9]
]
pdl> p $m->rot2d( 90, 0, 1 )
[
[0 0 0]
[3 6 9]
[2 5 8]
]
Looks good. Except for those pesky 0's. Where'd they come from? It
looks like it's rotating about the "6", not the "5", and filling in
the off-matrix values with my specified value of 0.
I'm tempted to call this an off-by-one error in the x direction, but
then I gave rot2d a nice even-sized matrix:
pdl> p $m = pdl( [ 1..4],[5..8],[9..12],[13..16])
[
[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]
[13 14 15 16]
]
pdl> p $m->rot2d( 90, 0, 1 )
[
[ 0 0 0 0]
[ 4 8 12 16]
[ 3 7 11 15]
[ 2 6 10 14]
]
with the same results. The x coord of the rotation center is
off-by-one from what I would consider the rotation center. Typically
such errors resolve themselves when switching from even to odd sizes,
so now I wonder if this is a feature rather than a bug.
There's a hard-coded 0.999999 in the code which gives me the willies,
but I haven't dissected it to figure out why it has the above
properties.
Any thoughts? Bug? Feature?