fork download
  1. function l = draw_links(link_set, link_colors, ax)
  2. % Draw a set of lines for a link structure into a specified axis
  3. %
  4. % Inputs:
  5. % link_set: A 1xn cell array, each entry of which is a matrix whose
  6. % columns are the endpoints of the lines describing one link
  7. % of the system.
  8. % link_colors: 1x3 cell array. Each entry can be either a standard
  9. % matlab color string (e.g., 'k' or 'r') or a 1x3 vector
  10. % of the RGB values for the color (range from 0 to 1).
  11. % ax: The handle to an axis in which to plot the links.
  12. %
  13. % Output:
  14. % l: A cell array of the same size as link_set, in which each entry is
  15. % a handle to a line structure for that link.
  16.  
  17. % Start by creating an empty cell array of the same size as link_set
  18. l = cell(size(link_set));
  19.  
  20. % Loop through each link in the link_set
  21. for i = 1:length(link_set)
  22. % Get the endpoints of the current link
  23. endpoints = link_set{i};
  24.  
  25. % Draw the link as a line between the endpoints
  26. % Assuming endpoints are structured as [x_start, x_end; y_start, y_end]
  27. line_handle = plot(ax, endpoints(1, :), endpoints(2, :), 'LineWidth', 2, 'Color', link_colors{i});
  28.  
  29. % Store the line handle in the cell array
  30. l{i} = line_handle;
  31.  
  32. % Draw circles at the endpoints
  33. hold(ax, 'on'); % Hold the axis to overlay the circles
  34. plot(ax, endpoints(1, 1), endpoints(2, 1), 'o', 'MarkerSize', 8, 'MarkerFaceColor', link_colors{i}); % Start point
  35. plot(ax, endpoints(1, 2), endpoints(2, 2), 'o', 'MarkerSize', 8, 'MarkerFaceColor', link_colors{i}); % End point
  36. end
  37.  
  38. hold(ax, 'off'); % Release the hold on the axis
  39. end
  40. % Define link vectors and joint angles
  41. link_vectors = {[1; 0], [1; 0]};
  42. joint_angles = [pi/4; -pi/2];
  43.  
  44. % Create link set
  45. link_set = planar_robot_arm_links(link_vectors, joint_angles);
  46.  
  47. % Create axes
  48. ax = create_axes();
  49.  
  50. % Define link colors
  51. link_colors = {'g', [0.5 0.5 0.5]}; % Green and Gray
  52.  
  53. % Draw links
  54. l = draw_links(link_set, link_colors, ax);
  55.  
Success #stdin #stdout #stderr 0.13s 48796KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
error: 'planar_robot_arm_links' undefined near line 45 column 12
error: called from
    /home/Vua53M/prog.octave at line 45 column 10