◆ __construct()
__construct |
( |
|
$rows, |
|
|
|
$columns, |
|
|
array |
$set = [] |
|
) |
| |
Matrix constructor.
- Parameters
-
71 $this->rows = max(1, (
int) $rows);
72 $this->columns = max(1, (
int) $columns);
◆ __toString()
- Returns
- string
278 for($r = 0; $r < $this->rows; ++$r){
279 $s .= implode(
",", $this->matrix[$r]) .
";";
282 return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) .
")";
◆ add()
- Parameters
-
- Returns
- bool|Matrix
145 if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
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));
◆ determinant()
- Returns
- bool|int
264 return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
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];
◆ divideScalar()
- Parameters
-
- Returns
- Matrix
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);
◆ getColumns()
- Returns
- int|mixed
99 return ($this->columns);
◆ getElement()
getElement |
( |
|
$row, |
|
|
|
$column |
|
) |
| |
- Parameters
-
- Returns
- bool
125 if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
129 return $this->matrix[(int) $row][(
int) $column];
◆ getRows()
◆ isSquare()
- Returns
- bool
136 return $this->rows === $this->columns;
◆ multiplyScalar()
multiplyScalar |
( |
|
$number | ) |
|
- Parameters
-
- Returns
- Matrix
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);
◆ offsetExists()
- Parameters
-
- Returns
- bool
36 return isset($this->matrix[(
int) $offset]);
◆ offsetGet()
- Parameters
-
- Returns
- mixed
45 return $this->matrix[(int) $offset];
◆ offsetSet()
offsetSet |
( |
|
$offset, |
|
|
|
$value |
|
) |
| |
- Parameters
-
53 $this->matrix[(int) $offset] = $value;
◆ offsetUnset()
- Parameters
-
60 unset($this->matrix[(
int) $offset]);
◆ product()
- Parameters
-
- Returns
- bool|Matrix
232 if($this->columns !== $matrix->getRows()){
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){
240 for($k = 0; $k < $this->columns; ++$k){
241 $sum += $this->matrix[$i][$k] * $matrix->getElement($k, $j);
243 $result->setElement($i, $j, $sum);
◆ set()
- Parameters
-
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;
◆ setElement()
setElement |
( |
|
$row, |
|
|
|
$column, |
|
|
|
$value |
|
) |
| |
- Parameters
-
- Returns
- bool
110 if($row > $this->rows or $row < 0 or $column > $this->columns or $column < 0){
113 $this->matrix[(int) $row][(
int) $column] = $value;
◆ substract()
- Parameters
-
- Returns
- bool|Matrix
164 if($this->rows !== $matrix->getRows() or $this->columns !== $matrix->getColumns()){
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));
◆ transpose()
- Returns
- Matrix
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]);
The documentation for this class was generated from the following file:
- src/pocketmine/math/Matrix.php