I need help with MATLAB homework Please help me with showing

I need help with (MATLAB) homework

Please help me with showing the steps

step by step please

turtle This is the main function for the assignment. You will be simulating the following. Imagine a little green turtle is dipped in black ink and then set loose. As it walks in a straight line, it leaves a trail of paint behind it. Every so often, the turtle turns some number of degrees and then continues moving. When the turtle is finally done moving, you will have a \"line in the sand\" that will show you were the turtle has been. Your job is to create this March of the Turtles in MATLAB. The turtle function takes in a bunch of information. start - the 2d point where the turtle starts direction - the 2d vector that the turtle is moving in distance - how far the turtle moves before turning turn - the number of degrees that the turtle turns each time repeats - the number of times the turtle moves and turns, moves and turns... Inside your function, you should: verify that number of inputs to the function is correct make sure the direction vector is normalized draw a line from where the turtle is to the next point the turtle will be at. turn the turtle repeat the previous 2 steps until the number of repeats is up. To compute where the turtle will be next, you can add the current location of the turtle to the direction vector multiplied by the distance variable. To figure out where the turtle is going next you can \"rotate_vector\" the direction vector.

Solution

I haven\'t used the draw_line function as info about is not provided in description

Code is self-explanatory(se comments of how it is working)

MATLAB CODE

function [ ] = turtle( start,direction,distance,turn,repeats )
%Simulation of turtle in sand
% start and direction are assumed to be row vectors, turn is assumed to be
% in degrees
% eg : turtle( [0,0],[1,1],5,45,4 )

% Checking number of arguments
if nargin~=5
    disp(\'Please check number of arguments, they should be 5 in order start,direction,distance,turn,repeats\');
    return;
end

% checking for regularized direction if not it will do it
norm_dir = norm(direction);
if norm_dir~=1
    direction = direction/norm_dir;
end

%Drawing first line
curr_point = start;
nxt_point = curr_point+distance*direction;
plot([curr_point(1),nxt_point(1)],[curr_point(2),nxt_point(2)]);
drawnow()
turn_vec = [cosd(turn),sind(turn); -sind(turn),cosd(turn)];
dir_vec = direction;
for i=1:repeats-1
    dir_vec = dir_vec*turn_vec;
    curr_point = nxt_point;
    nxt_point = curr_point+distance*dir_vec;
    plot([curr_point(1),nxt_point(1)],[curr_point(2),nxt_point(2)])
    drawnow()
    pause(2) % show line for two seconds
end


I need help with (MATLAB) homework Please help me with showing the steps step by step please turtle This is the main function for the assignment. You will be si
I need help with (MATLAB) homework Please help me with showing the steps step by step please turtle This is the main function for the assignment. You will be si

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site