jcklasseter has asked for the wisdom of the Perl Monks concerning the following question:
In essence, the script reads the input and assigns each line to a vector via the Math::Vector::Real module. My input file is like so:#!/usr/bin/perl use strict; use warnings; use Math::Vector::Real; use constant DEG_PER_RAD => 45 / atan2(1, 1); my ( $source, $out ) = qw/ IN OUT /; open my $in_fh, '<', $source or die qq{Unable to open "$source" for i +nput: $!\n}; open my $out_fh, '>', $out or die qq{Unable to open "$out" for outp +ut: $!\n}; #select $out_fh; my @data; push @data, V(split) while <$in_fh>; for my $i ( 0 .. $#data-1 ) { for my $j ( $i+1 .. $#data ) { my $val1 = $data[$i]; my $val2 = $data[$j]; my $comp1 = $val1->[0]; my $comp2 = $val2->[0]; my $vect1 = $val1->[3..5]; my $vect2 = $val2->[3..5]; my $norm = $val1->[0..2]; my $nvect1 = $vect1 - $norm ; my $nvect2 = $vect1 - $norm ; if( $comp1 != $comp2 ){ next;}else{ my $degrees = atan2($nvect1, $nvect2) * DEG_PER_RA +D; print "$degrees\n"; } } }
Which are location coordinates. The first 3 numbers on each line correspond to a point, and the other 3 in the line correspond to a nearby point. The first set will often be identical from line to line. The second set will never repeat between consecutive lines like the first. I'm trying to find the angle between the second set of coordinates between two separate rows, after normalizing them with respect to the first set of coordinates. The script works (via print testing) up until my $vect1 = $val1->[3..5];. When I print test here, I get: 2 (And a whole host of other errors that stem from this) I cannot find out how to split the values of a vector off into a new vector like I'm trying to. Does anyone have any ideas? Thanks.2 2 2 5 -2 1 2 2 2 2 7 4 5 2 2 2 7 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Vector manipulation (scalar)
by tye (Sage) on Jun 26, 2015 at 19:39 UTC | |
by jcklasseter (Sexton) on Jun 29, 2015 at 12:02 UTC | |
|
Re: Vector manipulation
by kcott (Archbishop) on Jun 27, 2015 at 07:12 UTC | |
by jcklasseter (Sexton) on Jun 29, 2015 at 11:34 UTC | |
|
Re: Vector manipulation
by tangent (Parson) on Jun 27, 2015 at 00:00 UTC | |
|
Re: Vector manipulation
by salva (Canon) on Jun 26, 2015 at 21:46 UTC |