- values are missing : A0 ,AL ,n ,step ,...
- function Newton_Raphson_Jansen not provided
Plotting upper and lower boundaries of a trace fuction
3 views (last 30 days)
Show older comments
Hi guys, I am seeking some help with a trace function.
I would like the trace line at the foor of this mechanism to change colour for -71 < x < -4 and y < -89, to show the upper and lower bounds of the trace but I am stuck and can't figure out how to alter the code for the animation below to reflect this in the sequence, I would really appreciate some help with this!
function [trace] = Jansen_trace(AL, A0, step, n)
% [trace] = Jansen_trace(AL, A0, step, cycles)
% This function plots the Jansen mechanical linkage and traces the foot of
% the mechanism using an initial angle and progressing these angles over a
% given step
% Input AL = Initial crank angle
% Input A0 = [A1_0 A2_0 A3_0 A4_0 A5_0 A6_0 A7_0 A8_0] Initial estimates
% for other angles
% Input step = Desired step for angle to increase by in radians
% Input n = number of cycles to execute
% Output coordinates = [nodei_x nodei_y;
% nodej_x nodej_y;
% nodek_x nodek_y;
% noden_x noden_y;
% nodem_x nodem_y;
% nodep_x nodep_y;
% node0_x node0_y;
% node1_x node1_y] positions of the joints after
% last cycle
% Version 1, 11/04/2024 by Conor Pierce, Student Number 21302251
if ~isvector(A0)
error('Input A0 is a 1 x 8 row vector')
end
if ~isscalar(n) || n < 0
error('Input n is a positive integer number of cycles to be performed.')
end
if step < 0 || step > pi/4
error('Step must be a positive angle increment between 0 and pi/4.')
end
if A0(1) < 0 || A0(2) < 0 || A0(3) < 0 || A0(4) < 0 || A0(5) < 0 || A0(6) < 0 || A0(7) < 0 || A0(8) < 0
error('Angle estimates must be positive.')
end
if A0(1) > 2*pi || A0(2) > 2*pi || A0(3) > 2*pi || A0(4) > 2*pi || A0(5) > 2*pi || A0(6) > 2*pi || A0(7) > 2*pi || A0(8) > 2*pi
error('Angle estimates cannot be greater than 2*pi.')
end
close all
A_est = A0;
A_crank = AL;
trace = zeros(2, floor(2*n*pi/step));
count = 1;
% Set the crank to begin at initial estimate, increase by the step for
% every set of NR operations
for A_crank = AL : step : A_crank + 2*pi*n
A_update = Newton_Raphson_Jansen(A_crank, A_est); % Update Angles
NODES = Nodepos(A_crank, A_update); % Update node positions
% x and y coordinates of nodes
nodei = [NODES(1, 1), NODES(1, 2)];
nodej = [NODES(2, 1), NODES(2, 2)];
nodek = [NODES(3, 1), NODES(3, 2)];
nodem = [NODES(4, 1), NODES(4, 2)];
noden = [NODES(5, 1), NODES(5, 2)];
nodep = [NODES(6, 1), NODES(6, 2)];
node0 = [NODES(7, 1), NODES(7, 2)];
node1 = [NODES(8, 1), NODES(8, 2)];
drawnow
clf
axis([-115 50 -100 60])
nodep_x = NODES(6, 1);
nodep_y = NODES(6, 2);
% Place a line trace at the foot of the mechanism
trace(1, count) = nodep(1);
trace(2, count) = nodep(2);
line(trace(1, 1:count), trace(2, 1:count));
% Connect the links together
line([node0(1) nodei(1)], [node0(2) nodei(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2, 'Marker', '.', 'MarkerSize', 20, 'MarkerEdgeColor', [0 0.5 0.2])
line([nodei(1) nodej(1)], [nodei(2) nodej(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([nodej(1) nodek(1)], [nodej(2) nodek(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([noden(1) nodem(1)], [noden(2) nodem(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([nodei(1) nodem(1)], [nodei(2) nodem(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([nodej(1) node1(1)], [nodej(2) node1(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([node1(1) nodem(1)], [node1(2) nodem(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([node1(1) nodek(1)], [node1(2) nodek(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([noden(1) nodep(1)], [noden(2) nodep(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([noden(1) nodep(1)], [noden(2) nodep(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([nodem(1) nodep(1)], [nodem(2) nodep(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
line([nodek(1) noden(1)], [nodek(2) noden(2)], 'Color', [0.1 0.1 1], 'Linewidth', 2)
A_est = A_update;
count = count + 1;
end
1 Comment
Mathieu NOE
on 19 Apr 2024
hi
we cannot run your code
Answers (0)
See Also
Categories
Find more on Geographic Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!