Avoiding drift while creating angular rotation with variable degree increments
Show older comments
Hello,
With the following code, I am trying to create a variable "deg" which should have small degree increments (ddeg_min) for deg<=angle and large increments (ddeg_max) for rest of a complete revolution. I want to repeat the same increments after completion of each revolution. For example, the increment should be 0.1 for 0<=deg<=16.0 and it should repeat the same thing after 360 degrees i.e. incr should be 0.1 for 360.1<=deg<=316.0. But, I am getting a drift in values e.g. 16.1 for first revolution and 366.1 for next revolution and so on.
It was hard to explain but I tried to make it as comprehendible as possible. Waiting for your kind suggestions, Thx.
close all
clear all
clc
phi=90;
angle=16;
ddeg_min=0.1;
ddeg_max=10;
deg(1)=0;
d_deg(1)=ddeg_min;
i=1;
while (1)
i=i+1;
revol_n=floor(deg(i-1)/360);
kkk=deg(i-1)-revol_n*360;
if (kkk >= 0 && kkk < angle)
d_deg(i)=ddeg_min;
deg(i)=deg(i-1)+d_deg(i);
else
d_deg(i)=ddeg_max;
deg(i)=deg(i-1)+d_deg(i);
end
if deg(i)>=1070
break
end
end
Accepted Answer
More Answers (1)
Mathieu NOE
on 24 Nov 2021
hello
why make things so complicated ?
this way you can generate the pattern for the first revolution . if you want to have it for multiple revolutions simply add 360 for each rev
close all
clear all
clc
phi=90;
angle=16;
ddeg_min=0.1;
ddeg_max=10;
% one revolution pattern
deg1 = (0:ddeg_min:angle);
deg2 = (angle+ddeg_max:ddeg_max:360);
deg = [deg1 deg2];
6 Comments
Waseem Akhtar
on 24 Nov 2021
Edited: Waseem Akhtar
on 24 Nov 2021
Mathieu NOE
on 24 Nov 2021
hello
you mean in the 0 - 360 range there would be 4 sectors with low increment and 4 sectors with large increment ?
this can be easily adapted using my code example
Waseem Akhtar
on 24 Nov 2021
Mathieu NOE
on 25 Nov 2021
as simple as this :
ddeg_min=0.1;
ddeg_max=10;
start_points = [0 90 180 270];
angle=16; % angular amplitude for refined resolution
deg = [];
% one revolution pattern
sectors = length(start_points);
for ci = 1:sectors
deg_fine = (start_points(ci):ddeg_min:start_points(ci)+angle);
if ci <= sectors-1
deg_coarse = (start_points(ci)+angle:ddeg_max:start_points(ci+1));
else % last sector (xx to 360)
deg_coarse = (start_points(ci)+angle:ddeg_max:360);
end
tmp = unique([deg_fine deg_coarse]); % remove duplicates
deg = [deg tmp]; % concatenate results for all sectors
end
plot(deg)
Waseem Akhtar
on 25 Nov 2021
Mathieu NOE
on 26 Nov 2021
My pleasure !
Categories
Find more on Mathematics 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!