What does the corresponding MATLAB code look like? I'd be interested to see how this could be improved---the below is kind of "yucky".
--Chris On Fri, Jul 8, 2011 at 12:10 AM, dpath2o <[email protected]> wrote: > Hi Craig and David, > > As you both alluded to this is not straightforward, and while I have a > solution that works for some cases it is not a general solution, but I'd > thought I'd report back an paste in the code here to see you have any > further insights: > > use strict; > use Math::Trig qw(:pi :radial :great_circle); > use PDL; > # input start ($b0) and stop ($bN) bearings AND delta_bearing ($db) > my ($b0,$bN,$db) = (,220,10); > # convert geographic bearings in degrees true North to cartesian > (trigonometric) angles such that 0 degrees is no longer north but is now > horizontal with x-axis, convert all to radians > $b0 = (pi*$b0)/180; #radian conversion > $b0 -= pi/90; #angle translation > $bN = (pi*$bN)/180; #radian coversion > $bN -= pi/90; #angle translation > $db = (pi*$db)/180; #radian conversion > # create bearing piddle > my $pdl; > if ($bN<$b0) { #if coverage wraps over 2*pi > my $i_Na = int(abs($b0-(pi*2))/$db)+1; > my $i_Nb = int(abs($bN-0)/$db)+1; > my $a = zeroes($i_Na); > my $b = zeroes($i_Nb); > $a .= $a->xlinvals($b0,(pi*2)); > $b .= $b->xlinvals($db,$bN); > $pdl = $a->append($b); > } else { > my $i_N = int(abs($b0-$bN)/$db) + 1; > $pdl = zeroes($i_N); > $pdl .= $pdl->xlinvals($b0,$bN); > } > $pdl .= floor( (180*$pdl)/pi ); > print "$pdl\n"; > On 8 July 2011 00:29, David Mertens <[email protected]> wrote: >> >> Hello Daniel, >> >> I'm not entirely sure what you're trying to do, so I can't answer by >> changing your supplied code. I can, however, point out a couple of >> things. >> >> PDL does not have a straight equivalent to matlab's start:step:end >> notation, at least not for pdl creation. The slicing notation does >> allow you to specify strides using a start:end:stride notation: >> >> --------%<-------- >> use strict; use warnings; use PDL; >> use PDL::NIceSlice; >> my $original = sequence(20); >> my ($start, $end, $stride) = (2, 19, 3); >> my $slice = $original($start:$end:$stride); >> -------->%-------- >> >> Craig already mentioned xvals, rvals, and the others. Something that >> is even closer to what you want is the set of functions >> xlinvals(start, stop), ylinvals(start, stop), zlinvals(start, stop). >> Like xvals and rvals, these functions are not constructors; they take >> the invoking pdl and use it as a template, computing the necessary >> spacing so that the first value is $start and the last value is $stop, >> with linear steps in between them. That means you'll have to determine >> the number of elements and create a template pdl separately, like >> this: >> >> --------%<-------- >> use strict; use warnings; use PDL; >> my ($start, $end, $step) = (2, 19, 0.1); >> my $N_elements = int (abs($end - $start) / $step) + 1; >> my $pdl = zeroes($N_elements); >> $pdl .= $pdl->xlinvals($start, $end); >> -------->%-------- >> >> This code does not handle edge cases very well. For example, if the >> step does not divide evenly into $end - $start, then the resulting pdl >> will not have the specified stride. However, hopefully it will get you >> started. Perhaps the two-argument form of xlinvals et al can be >> extended to a three argument form, which would actually be a >> constructor and would do what the Matlab constructor does. >> >> David >> >> -- >> Sent via my carrier pigeon. > > > _______________________________________________ > Perldl mailing list > [email protected] > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
