GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Matrix Class Reference

Public Member Functions

 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 __construct ($rows, $columns, array $set=[])
 
 set (array $m)
 
 getRows ()
 
 getColumns ()
 
 setElement ($row, $column, $value)
 
 getElement ($row, $column)
 
 isSquare ()
 
 add (Matrix $matrix)
 
 substract (Matrix $matrix)
 
 multiplyScalar ($number)
 
 divideScalar ($number)
 
 transpose ()
 
 product (Matrix $matrix)
 
 determinant ()
 
 __toString ()
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $rows,
  $columns,
array  $set = [] 
)

Matrix constructor.

Parameters
$rows
$columns
array$set
70  {
71  $this->rows = max(1, (int) $rows);
72  $this->columns = max(1, (int) $columns);
73  $this->set($set);
74  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string
276  {
277  $s = "";
278  for($r = 0; $r < $this->rows; ++$r){
279  $s .= implode(",", $this->matrix[$r]) . ";";
280  }
281 
282  return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")";
283  }

◆ add()

add ( Matrix  $matrix)
Parameters
Matrix$matrix
Returns
bool|Matrix
144  {
145  if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
146  return false;
147  }
148  $result = new Matrix($this->rows, $this->columns);
149  for($r = 0; $r < $this->rows; ++$r){
150  for($c = 0; $c < $this->columns; ++$c){
151  $result->setElement($r, $c, $this->matrix[$r][$c] + $matrix->getElement($r, $c));
152  }
153  }
154 
155  return $result;
156  }

◆ determinant()

determinant ( )
Returns
bool|int
256  {
257  if($this->isSquare() !== true){
258  return false;
259  }
260  switch($this->rows){
261  case 1:
262  return 0;
263  case 2:
264  return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
265  case 3:
266  return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
267  }
268 
269  return false;
270  }

◆ divideScalar()

divideScalar (   $number)
Parameters
$number
Returns
Matrix
199  {
200  $result = clone $this;
201  for($r = 0; $r < $this->rows; ++$r){
202  for($c = 0; $c < $this->columns; ++$c){
203  $result->setElement($r, $c, $this->matrix[$r][$c] / $number);
204  }
205  }
206 
207  return $result;
208  }

◆ getColumns()

getColumns ( )
Returns
int|mixed
98  {
99  return ($this->columns);
100  }

◆ getElement()

getElement (   $row,
  $column 
)
Parameters
$row
$column
Returns
bool
124  {
125  if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
126  return false;
127  }
128 
129  return $this->matrix[(int) $row][(int) $column];
130  }

◆ getRows()

getRows ( )
Returns
int|mixed
91  {
92  return ($this->rows);
93  }

◆ isSquare()

isSquare ( )
Returns
bool
135  {
136  return $this->rows === $this->columns;
137  }

◆ multiplyScalar()

multiplyScalar (   $number)
Parameters
$number
Returns
Matrix
182  {
183  $result = clone $this;
184  for($r = 0; $r < $this->rows; ++$r){
185  for($c = 0; $c < $this->columns; ++$c){
186  $result->setElement($r, $c, $this->matrix[$r][$c] * $number);
187  }
188  }
189 
190  return $result;
191  }

◆ offsetExists()

offsetExists (   $offset)
Parameters
mixed$offset
Returns
bool
35  {
36  return isset($this->matrix[(int) $offset]);
37  }

◆ offsetGet()

offsetGet (   $offset)
Parameters
mixed$offset
Returns
mixed
44  {
45  return $this->matrix[(int) $offset];
46  }

◆ offsetSet()

offsetSet (   $offset,
  $value 
)
Parameters
mixed$offset
mixed$value
52  {
53  $this->matrix[(int) $offset] = $value;
54  }

◆ offsetUnset()

offsetUnset (   $offset)
Parameters
mixed$offset
59  {
60  unset($this->matrix[(int) $offset]);
61  }

◆ product()

product ( Matrix  $matrix)
Parameters
Matrix$matrix
Returns
bool|Matrix
231  {
232  if($this->columns !== $matrix->getRows()){
233  return false;
234  }
235  $c = $matrix->getColumns();
236  $result = new Matrix($this->rows, $c);
237  for($i = 0; $i < $this->rows; ++$i){
238  for($j = 0; $j < $c; ++$j){
239  $sum = 0;
240  for($k = 0; $k < $this->columns; ++$k){
241  $sum += $this->matrix[$i][$k] * $matrix->getElement($k, $j);
242  }
243  $result->setElement($i, $j, $sum);
244  }
245  }
246 
247  return $result;
248  }

◆ set()

set ( array  $m)
Parameters
array$m
79  {
80  for($r = 0; $r < $this->rows; ++$r){
81  $this->matrix[$r] = [];
82  for($c = 0; $c < $this->columns; ++$c){
83  $this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0;
84  }
85  }
86  }

◆ setElement()

setElement (   $row,
  $column,
  $value 
)
Parameters
$row
$column
$value
Returns
bool
109  {
110  if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
111  return false;
112  }
113  $this->matrix[(int) $row][(int) $column] = $value;
114 
115  return true;
116  }

◆ substract()

substract ( Matrix  $matrix)
Parameters
Matrix$matrix
Returns
bool|Matrix
163  {
164  if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
165  return false;
166  }
167  $result = clone $this;
168  for($r = 0; $r < $this->rows; ++$r){
169  for($c = 0; $c < $this->columns; ++$c){
170  $result->setElement($r, $c, $this->matrix[$r][$c] - $matrix->getElement($r, $c));
171  }
172  }
173 
174  return $result;
175  }

◆ transpose()

transpose ( )
Returns
Matrix
213  {
214  $result = new Matrix($this->columns, $this->rows);
215  for($r = 0; $r < $this->rows; ++$r){
216  for($c = 0; $c < $this->columns; ++$c){
217  $result->setElement($c, $r, $this->matrix[$r][$c]);
218  }
219  }
220 
221  return $result;
222  }

The documentation for this class was generated from the following file: