Example #1
0
 public function Apply($target)
 {
     if ($target instanceof ALiVE_Matrix) {
         return ALiVE_Matrices_Multiply($target, $this->ToMatrix());
     } else {
         if ($target instanceof ALiVE_Vector) {
             return new ALiVE_2D_Vector($this->Apply($target->ToMatrix()));
         } else {
             if (is_array($target)) {
                 foreach ($target as $vector) {
                     w_assert($vector instanceof ALiVE_Vector);
                 }
                 $result = $this->Apply(ALiVE_Vectors_ToMatrix($target));
                 $ret = array();
                 for ($i = 0; $i < $result->M(); ++$i) {
                     $thismatrix = new ALiVE_Matrix(1, 4);
                     $thismatrix->Set(0, 0, $result->Get($i, 0));
                     $thismatrix->Set(0, 1, $result->Get($i, 1));
                     $thismatrix->Set(0, 2, $result->Get($i, 2));
                     $thismatrix->Set(0, 3, $result->Get($i, 3));
                     $ret[] = new ALiVE_2D_Vector($thismatrix);
                 }
                 return $ret;
             }
         }
     }
     throw new Exception('Invalid projection application argument');
 }
Example #2
0
 public function Power($pow)
 {
     w_assert(is_int($pow) && $pow >= 0);
     switch ($pow) {
         case 1:
             return clone $this;
         default:
             $result = ALiVE_Matrix_Create_Identity($this->Order());
             for ($i = 0; $i < $pow; ++$i) {
                 $result = ALiVE_Matrices_Multiply($result, $this);
             }
             return $result;
     }
 }