doozy has asked for the wisdom of the Perl Monks concerning the following question:
I have 300+ objects with specific values for x,y,z coordinates, and I want to determine the distance between all 300+ objects and construct a matrix in the following fashion-
A B C A 0 10 3 B 4 0 7 C 4 1 0
where the values in the matrix are the distances between A and B, A and C etc. (I just made up the numbers). I've been given data like so,
s x y z A C 79.620 54.720 53.034 B C 81.822 54.071 50.027 C C 83.871 51.966 52.424 ...
And this equation for distance:
$d = sqrt(($rx1 - $rx2)**2 + ($ry1 - $ry2)**2 + ($rz1 - $rz2)**2)
s is a shape parameter that doesn't do anything for this calculation. I realize that I need to work with loops in order to do these crazy number of permutations, but I am not sure how to begin. I tried the following way to get a code to read and store the values in the file, but I could only get it read the first line.
open(IN, "template.xyz") or die; chomp($line = < IN >); ($b, @xyz) = split /\s+/, $line; while (chomp($line = < IN >)) { ($bb, @xyzvals) = split /\s+/, $line; for ($i=0; $i<@xyzvals; $i++) { $s{$bb}{$xyz[$i]} = $xyzvals[$i]; } } close(IN);
Any advice on reading/storing the values properly and how to go about doing the permutations?
Original content restored above by GrandFather
I have 300+ objects with specific values for certain coordinates, and I want to determine a value between all 300+ objects and construct a matrix. Any advice on reading/storing the values properly and how to go about doing the permutations? (question resolved)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Employing loops and constructing a matrix
by NetWallah (Canon) on Apr 24, 2012 at 05:07 UTC | |
|
Re: Employing loops and constructing a matrix
by jwkrahn (Abbot) on Apr 24, 2012 at 05:50 UTC |