Help with drawing lines at a constant angle (60 degrees) to another line starting from a known point.
7 views (last 30 days)
Show older comments
Hi everyone. I have a circular region of interest (ROI) that I got using roipoly, and then I used the regionprops function to get the center (centroid) of the ROI. Now, I have a known line that runs from the center of the ROI to an arbitrary point on the circle. That task I have at hand is to draw five other lines that will be at an angle of 60 degrees to each other starting with this known line. Kindly help if you've got an idea. Thank you in advance. Please find below my code (Uncomment all lines once and remove if true line to run the code):
<<
>>
if true
% Image = imread('pout.tif');
% figure(100), imshow(Image);
% disp('Draw the ROI ellipse:)');
% roi_image = imellipse;
% binaryImage = roi_image.createMask();
% figure(100), imshow(binaryImage);
% s = regionprops(binaryImage,'Centroid');
% disp('Click a point on the circumference of the ROI :)');
% [x_rv,y_rv] = ginput(1);
% line_lenc = pdist([s.Centroid(1),s.Centroid(2);x_rv,y_rv],'euclidean');
% hold on
% plot(s.Centroid(1),s.Centroid(2), 'b*');
% plot(x_rv,y_rv, 'b*'); % Plot the
% theta = 0:60:300; % Angle of the lines
% xEnd = s.Centroid(1)+line_lenc*cosd(theta); % x coordinates
% yEnd = s.Centroid(2)+line_lenc*sind(theta); % y coordinates
% % xEnd(1) = x_rv;
% % yEnd(1) = y_rv;
% for i = 1:length(theta)
% imline(gca,[s.Centroid(1) xEnd(i)], [s.Centroid(2) yEnd(i)]);
% end
% hold off
0 Comments
Answers (2)
Jonathan Kwang
on 12 Aug 2016
You could add a "addNewPositionCallback" callback function to each of the lines. Then in this callback function you can calculate and redraw the other lines to be offset by 60 degrees from the line that was moved.
This requires you to store the handles of each of the imlines to an array so you can modify them when a line is moved.
lineHandles(i)=imline(gca,[s.Centroid(1) xEnd(i)], [s.Centroid(2) yEnd(i)]);
Then also add a callback function to each imline:
addNewPositionCallback(lineHandles(i),@(pos)callback_line(pos,i));
and your callback function would look something like this:
function callback_line(pos,i)
% Redraw the other imlines that are not the one stored at lineHandles(i)
end
A similar example of this technique that keeps 2 lines perpendicular to each other can be found at the following link: http://stackoverflow.com/questions/24141891/draw-2-imline-to-be-perpendicular-to-each-other-matlab
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!