how to divise an image on 2d to 6 segments with matrix rotation ?
1 view (last 30 days)
Show older comments
heyy, i want to divise an image with matrix rotation to 6 segments (theta=60degrees),the point is to incrimente a new segment with the last segment (by theta=theta+pi/3).can u help me please
x = 1:5;
y = 1:5;
v = [x;y];
x_center = x(3);
y_center = y(3);
center = repmat([x_center; y_center], 1, length(x));
theta = pi/3;
mod(theta,360)
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
s = v - center;
so = R*s;
vo = so + center;
x_rotated = vo(1,:);
y_rotated = vo(2,:);
plot(x, y, 'k-', x_rotated, y_rotated, 'r-', x_center, y_center, 'bo');
axis equal
x_rotated = 1:5;
y_rotated = 1:5;
v1 = [x_rotated;y_rotated];
x1_center = x_rotated(3);
y1_center = y_rotated(3);
center1 = repmat([x1_center; y1_center], 1, length(x_rotated));
theta1=theta+pi/3;
R1 = [cos(theta1) -sin(theta1); sin(theta1) cos(theta1)];
s1 = v1 - center1;
so1 = R1*s1;
vo1 = so1 + center1;
x1_rotated = vo1(1,:);
y1_rotated = vo1(2,:);
plot(x_rotated, y_rotated, 'k-', x1_rotated, y1_rotated, 'b-', x1_center, y1_center, 'bo');
axis equal
the problem in my code that he couldn't show the first segment with 60degrees,it shows only the last one with 120degrees
Accepted Answer
Guillaume
on 16 Jul 2018
Note that you should isolate your rotating matrix code into its own function or use a for loop instead of duplicating it.
Also note that since R2016b, you don't need to repmat your centre vector and prior to R2016b bsxfun is faster than repmat.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!