Repository navigation
Expand file tree
/
Copy pathupdate_leg_drawing.m
More file actions
66 lines (58 loc) · 2.73 KB
/
Copy pathupdate_leg_drawing.m
File metadata and controls
66 lines (58 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%Updates the plot objects that visualize the leg linkage
%for the current leg configuration
%INPUTS:
%vertex_coords_root: a column vector containing the (x,y) coordinates of every vertex
%leg_drawing: a struct containing all the plotting objects for the linkage
% leg_drawing.linkages is a cell array, where each element corresponds
% to a plot of a single link (excluding the crank)
% leg_drawing.crank is a plot of the crank link
% leg_drawing.vertices is a cell array, where each element corresponds
% to a plot of one of the vertices in the linkage
function update_leg_drawing(vertex_coords_root, leg_drawing, leg_params)
num_vertices=leg_params.num_vertices;
num_linkages=leg_params.num_linkages;
link_to_vertex_list=leg_params.link_to_vertex_list;
link_lengths=leg_params.link_lengths;
crank_length=leg_params.crank_length;
vertex_pos0=leg_params.vertex_pos0;
vertex_pos2=leg_params.vertex_pos2;
vertex_coords_mat=column_to_matrix(vertex_coords_root);
%iterate through each link, and update corresponding link plot
for linkage_index = 1:leg_params.num_linkages
%linkage_index is the label of the current link
%your code here
a_vertex=link_to_vertex_list(linkage_index,1);
b_vertex=link_to_vertex_list(linkage_index,2);
x_a=vertex_coords_mat(a_vertex,1);
y_a=vertex_coords_mat(a_vertex,2);
x_b=vertex_coords_mat(b_vertex,1);
y_b=vertex_coords_mat(b_vertex,2);
%line_x and line_y should both be two element arrays containing
%the x and y coordinates of the line segment describing the current link
line_x = [x_a, x_b];%your code here
line_y = [y_a, y_b];%your code here
set(leg_drawing.linkages{linkage_index},'xdata',line_x,'ydata',line_y);
end
%iterate through each vertex, and update corresponding vertex plot
for vertex_index = 1:leg_params.num_vertices
%vertex_index is the label of the current vertex
%your code here
x_i=vertex_coords_mat(vertex_index,1);
y_i=vertex_coords_mat(vertex_index,2);
%dot_x and dot_y should both be scalars
%specifically the x and y coordinates of the corresponding vertex
dot_x = x_i;%your code here
dot_y = y_i;%your code here
set(leg_drawing.vertices{vertex_index},'xdata',dot_x,'ydata',dot_y);
end
%your code here
x1=vertex_coords_mat(1,1);
y1=vertex_coords_mat(1,2);
x0=vertex_pos0(1);
y0=vertex_pos0(2);
%crank_x and crank_y should both be two element arrays
%containing the x and y coordinates of the line segment describing the crank
crank_x = [x0,x1];%your code here
crank_y = [y0,y1];%your code here
set(leg_drawing.crank,'xdata',crank_x,'ydata',crank_y);
end