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

14 ビュー (過去 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 月 12 日
Thank you so much Jonathan. I'll try your suggestions, and give you a feedback...
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