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'); }
public function Opposite() { $result = new ALiVE_Matrix($this->Order()); for ($i = 0; $i < $result->M(); ++$i) { for ($j = 0; $j < $result->N(); ++$j) { $result->Set($i, $j, -$this->Get($i, $j)); } } return $result; }
function ALiVE_Vectors_ToMatrix($vectors) { w_assert(is_array($vectors) && count($vectors)); $result = new ALiVE_Matrix(count($vectors), 4); $j = 0; foreach ($vectors as $vector) { w_assert($vector instanceof ALiVE_Vector); $result->Set($j, 0, $vector->X()); $result->Set($j, 1, $vector->Y()); $result->Set($j, 2, $vector->Z()); $result->Set($j, 3, 1); ++$j; } return $result; }