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

6 次查看(过去 30 天)
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

回答(2 个)

Jonathan Kwang
Jonathan Kwang 2016-8-12
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
  2 个评论
Fizzle
Fizzle 2016-8-15
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
Ceylan Sonmez 2018-7-11
Have you had a solution to your question?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by