I have create a circle and, using ginput, select two points on the circumference of that circle, create a line between those two points and then calculate the distance. This is what I have so far:
Array = linspace(0, 2*pi, 200);
x = cos(Array);
y = sin(Array);
plot(x,y)
[x1, y1] = ginput(2)
plot(x1,y1)
Distance = sqrt(x1.^2+y1.^2)
My problem is how do I confirm that the points selected are actually on the circumference, or is there a specific ginput I can use that will only allow me to select points from that circle.
Creating the line isn't a problem, but calculating the distance is (the distance formula above still comes back with two numbers).
Thanks

 채택된 답변

Image Analyst
Image Analyst 2013년 11월 28일

0 개 추천

Try this:
Array = linspace(0, 2*pi, 200);
x = cos(Array);
y = sin(Array);
plot(x,y, 'bo-')
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
promptMessage = sprintf('Click two points,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
[twoPointsX, twoPointsY] = ginput(2)
hold on;
plot(twoPointsX,twoPointsY, 'rd')
% Find the point closest to the first clicked point.
distances = sqrt((x - twoPointsX(1)) .^2 + (y - twoPointsY(1)) .^ 2)
[minDistance1, index1] = min(distances)
% Find the point closest to the Second clicked point.
distances = sqrt((x - twoPointsX(2)) .^2 + (y - twoPointsY(2)) .^ 2)
[minDistance2, index2] = min(distances)
% Plot the points on the circumference in red squares.
plot([x(index1), x(index2)], [y(index1), y(index2)], 'rs-')
% Calculate the final distance:
distance = sqrt( (x(index1)-x(index2))^2 + (y(index1)-y(index2))^2)
message = sprintf('The distance = %f', distance);
uiwait(helpdlg(message));

댓글 수: 2

Image Analyst
Image Analyst 2013년 11월 28일
Ada
Ada 2013년 11월 28일
편집: Ada 2013년 11월 28일
This was exactly was I was looking for, specifically the part that locates the nearest point on the circle. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

질문:

Ada
2013년 11월 28일

편집:

Ada
2013년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by