Help with drawing lines at a constant angle (60 degrees) to another line starting from a known point.

12 views (last 30 days)
Fizzle on 7 Aug 2016
Answered: Ceylan Sonmez on 11 Jul 2018
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
% figure(100), imshow(Image);
% disp('Draw the ROI ellipse:)');
% roi_image = imellipse;
% 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

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:
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
Fizzle on 15 Aug 2016
Hi Jonathan. I've tried to implement your suggestion, but I don't exactly get it. Perhaps I'm still a matlab rookie. That said, I don't necessarily want to be able to drag the six line, I just want the first line to start from a point that I specify by my single click, and all other five lines drawn relative to it (at an angle of 60 degree to each other). This is what I mean in picture. Please help me out with this. Thanks in advance... Ceylan Sonmez on 11 Jul 2018