How to change the visualization from lines to a patch
Mostra commenti meno recenti
I have a robot maze that is in 2d and im trying to make it 3d. Currently the walls are lines and I need to turn them to patches but i'm not sure how to do this?
function [maze_figure, maze_axes] = drawMaze3d(maze)
% prepare figure and axes
maze_figure = figure;
maze_axes = axes;
axis equal;
hold on;
title('this will become the 3d maze')
% set axis properties depending on maze size
axis([0 maze.number_of_columns 0 maze.number_of_rows+2]);
set(gca, 'xlim', [0 maze.number_of_columns], 'ylim', [2 maze.number_of_rows+2], 'xtick', [], 'ytick', []);
set(gca, 'xtick', [], 'ytick', [], 'ztick', []);
view(30, 30)
% ----------------------------------------------------------------------------------------------------------------------
% remove this line and specify camera properties of the maze_axes here for (b)
% ----------------------------------------------------------------------------------------------------------------------
% draw the grid
for i_col = 1:maze.number_of_columns
for i_row = 1:maze.number_of_rows
% draw the northern wall
if maze.hasWall(i_row, i_col, 1)
drawWallNorth(maze, i_row, i_col);
end
% draw the eastern wall
if maze.hasWall(i_row, i_col, 2)
drawWallEast(maze, i_row, i_col);
end
% draw the southern wall
if maze.hasWall(i_row, i_col, 3)
drawWallSouth(maze, i_row, i_col);
end
% draw the western wall
if maze.hasWall(i_row, i_col, 4)
drawWallWest(maze, i_row, i_col);
end
end
end
end
% nested functions
function drawWallNorth(maze, row, column)
x1 = column-1;
x2 = column;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 3;
plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallEast(maze, row, column)
x1 = column;
x2 = column;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 2;
plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallSouth(maze, row, column)
x1 = column-1;
x2 = column;
y1 = maze.number_of_rows - row + 2;
y2 = maze.number_of_rows - row + 2;
plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
function drawWallWest(maze, row, column)
x1 = column-1;
x2 = column-1;
y1 = maze.number_of_rows - row + 3;
y2 = maze.number_of_rows - row + 2;
plot([x1, x2], [y1, y2], 'k', 'linewidth', 4);
% ----------------------------------------------------------------------------------------------------------------------
% add a 3d patch here for (a)
% ----------------------------------------------------------------------------------------------------------------------
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Labyrinth problems in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


