# this works as a bash include
#
#PRIO 1.1
#COMM Math::GeometNdPoint->scalar_prod() in 3D
#COMM - monitor scalar product over successive rotations on a vector copy
#COMM   check result versus cosinus of rotation angle.
#
perl -e '
  use lib shift();  # give include precedence to code directory, perl -I would not work!
  use strict;
  use Math::GeometNdPoint;
  use Math::GeometNdTrform;
  my $pPt1 = Math::GeometNdPoint->new(3,[1,0,0]);
  my $pPt2 = $pPt1->clone();
  our $pi=3.14;
  our $nstep=6;
  our $wstep=$pi/($nstep-1);
  print  "--- method scalar_prod() ---\n";
  my $pTf = Math::GeometNdTrform->new_rotate(3,0,1,$wstep);
  for (my $a=0,my $i=0; $a<$pi*1.001; $a+=$wstep,++$i){
    my $p = $pPt1->scalar_prod($pPt2);
    printf "rotation %d/%d*pi: scalar product %.2f, cosinus %.2f\n",
      $i, $nstep-1, $p, cos($a);
    $pPt2->transform($pTf);
  }
  print  "--- method strip_vector() ---\n";
  our $ndim=3;
  my @vec;
  @vec = map { Math::GeometNdPoint->new($ndim,@$_) }
    [ 0, 0, 0 ], [ -2, 4, 3 ];
  printf "%s, stripped %s\n",
    $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f)),
    $vec[1]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  $vec[0]->strip_vector($vec[1]);
  printf "-> %s\n", $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  @vec = map { Math::GeometNdPoint->new($ndim,@$_) }
    [ -2, 4, 3 ], [ 0, 0, 0 ];
  printf "%s, stripped %s\n",
    $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f)),
    $vec[1]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  $vec[0]->strip_vector($vec[1]);
  printf "-> %s\n", $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  @vec = map { Math::GeometNdPoint->new($ndim,@$_) }
    [ 1, 1, 1 ], [ -2, 4, 3 ];
  printf "%s, stripped %s\n",
    $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f)),
    $vec[1]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  $vec[0]->strip_vector($vec[1]);
  printf "-> %s\n", $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  @vec = map { Math::GeometNdPoint->new($ndim,@$_) }
    [ 1, 1, 1 ], [ 0, 0, -2 ];
  printf "%s, stripped %s\n",
    $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f)),
    $vec[1]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  $vec[0]->strip_vector($vec[1]);
  printf "-> %s\n", $vec[0]->string(-label=>q(vector),-fmtfloat=>q(%.2f));
  ' -- "$dircode"
