public static function antidiagonal(Matrix $matrix)
    {
        if (!$matrix->isSquare()) {
            throw new Exception('Anti-Diagonal can only be extracted from a square matrix');
        }

        $dimensions = $matrix->rows;
        $grid = Builder::createFilledMatrix(0, $dimensions, $dimensions)
            ->toArray();

        for ($i = 0; $i < $dimensions; ++$i) {
            $grid[$i][$dimensions - $i - 1] = $matrix->getValue($i + 1, $dimensions - $i);
        }

        return new Matrix($grid);
    }
public static function antidiagonal(Matrix $matrix)
    {
        if (!$matrix->isSquare()) {
            throw new Exception('Anti-Diagonal can only be extracted from a square matrix');
        }

        $dimensions = $matrix->rows;
        $grid = Builder::createFilledMatrix(0, $dimensions, $dimensions)
            ->toArray();

        for ($i = 0; $i < $dimensions; ++$i) {
            $grid[$i][$dimensions - $i - 1] = $matrix->getValue($i + 1, $dimensions - $i);
        }

        return new Matrix($grid);
    }
public static function antidiagonal ( Matrix $ matrix ) { if ( ! $ matrix -> isSquare ( ) ) { throw new Exception ( 'Anti-Diagonal can only be extracted from a square matrix' ) ; } $ dimensions = $ matrix -> rows ; $ grid = Builder :: createFilledMatrix ( 0 , $ dimensions , $ dimensions ) -> toArray ( ) ; for ( $ i = 0 ; $ i < $ dimensions ; ++ $ i ) { $ grid [ $ i ] [ $ dimensions - $ i - 1 ] = $ matrix -> getValue ( $ i + 1 , $ dimensions - $ i ) ; } return new Matrix ( $ grid ) ; }
Return the antidiagonal of this matrix

@param Matrix $matrix The matrix whose antidiagonal we wish to calculate
@return Matrix
@throws Exception
Return the antidiagonal of this matrix