Mercurial > hg > Members > kono > Cerium
diff old/tmp/outer.pl @ 598:a64e729a8072
normal vector fix script
author | e065725@kinjyo.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 05 Nov 2009 22:00:10 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/old/tmp/outer.pl Thu Nov 05 22:00:10 2009 +0900 @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +# fix Cerium xml normal vector + +my $i = -1; +my (@x,@y,@z); +my @cord; +my $fix = 1; + +sub v { + print "$x[0] $y[0] $z[0]\n"; + print "$x[1] $y[1] $z[1]\n"; + print "$x[2] $y[2] $z[2]\n"; +} + +sub outer { + my ($ax,$ay,$az) = ( + $x[1]-$x[0], + $y[1]-$y[0], + $z[1]-$z[0], + ); + my ($bx,$by,$bz) = ( + $x[2]-$x[0], + $y[2]-$y[0], + $z[2]-$z[0], + ); + my ($ox,$oy,$oz) = ( + $ay*$bz - $az*$by, + -$ax*$bz + $az*$bx, + $ax*$by - $ay*$bx, + ); + my($r) = sqrt($ox*$ox+$oy*$oy+$oz*$oz); + ($ox,$oy,$oz) = ($ox/$r,$oy/$r,$oz/$r); + push(@cord, [$ox,$oy,$oz]); + # print " $ox $oy $oz\n"; +} + +while(<>) { + if (! $fix) { + if (/<sur/) { + print; + next; + } + } + if (/<normal/) { + $i= -2; + print if ($fix); + next; + } + if (/<\/normal/) { + $i = -1; + print if ($fix); + next; + } + if ( $i < -1) { + if ($i== -4) { + my $cord = shift(@cord); + if ($fix) { + print " $cord->[0] $cord->[1] $cord->[2] \n"; + print " $cord->[0] $cord->[1] $cord->[2] \n"; + print " $cord->[0] $cord->[1] $cord->[2] \n"; + } else { + print "outer $i $cord->[0] $cord->[1] $cord->[2] \n"; + print ; + } + $i = -2; + } else { + $i--; + } + next; + } + print if ($fix); + if (/<\/coord/) { + $i = -1; + next; + } + if (/<coord/) { + @cord = (); + $i=0; + next; + } + if ($i<0) { + next; + } + if (/([-]*[.\d]+)\s+([-]*[.\d]+)\s+([-]*[.\d]+)/) { + ($x[$i],$y[$i],$z[$i]) = ($1,$2,$3); +# print "$i $_"; + if ($i==2) { + &outer; + $i = 0; + next; + } + $i++; + } else { + $i = -1; + } +} + +# end