How to find where a circle lie between which range?

조회 수: 9 (최근 30일)
Abdel-Rahman Eltaib
Abdel-Rahman Eltaib 2021년 12월 28일
답변: Adam Danz 2021년 12월 28일
Ive a probelem where I need to caclculate the score of the bullet holes or makings. I was able to find the bullet holes or small circles, and was also able to detect the ranges or big circles. I just to make a loop that will detect where these small circles lie between which range.
  댓글 수: 1
Sargondjani
Sargondjani 2021년 12월 28일
Can you be more specific about your problem?
I mean, if you can find each bullet hole, then you already have some kind of loop? So I don't understand why you can identify the position of each circle.
Maybe provide a minimum working example (or short version of your code).

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

채택된 답변

Adam Danz
Adam Danz 2021년 12월 28일
  1. Convert the (x,y) coordinates of the 5 holes to polar coordinates using [theta,rho]=cart2pol(x,y)
  2. The rho values are the radial distances from the hole coordinates to the center of the target. Compare those results against the eccentricities of the rings to determine which ring each hole belongs to.
Demo
Create target and holes
cla
hold on
radii = 1:10;
theta = linspace(0,2*pi);
for r = radii
plot(r*sin(theta), r*cos(theta), 'r-')
end
axis equal
% add holes
rng('default') % for reproducibility
[xHole, yHole] = pol2cart(2*pi*rand(1,5), 10*rand(1,5));
plot(xHole, yHole, 'k*', 'MarkerSize', 10, 'LineWidth', 1)
% Label bands
text(radii, radii*0, compose('%g',radii),'HorizontalAlignment','right')
Given coordinates of holes (xHole, yHole) and the radii of target bands (radii), identify the band that contains each hole.
% Measure distance to center
[~, holeRad] = cart2pol(xHole, yHole);
radiiInf = [radii, inf]; % to account for holes outside of outer ring
% Identify band for each hole
[~, bandIdx] = max(holeRad(:) <= radiiInf,[],2);
holeBand = radiiInf(bandIdx);
% Show results in table
T = table(xHole(:), yHole(:), holeRad(:), holeBand(:), ...
'VariableNames', {'x','y','Distance','Band'})
T = 5×4 table
x y Distance Band _______ ________ ________ ____ 0.38582 -0.89585 0.9754 1 2.3112 -1.5539 2.785 3 3.8185 3.915 5.4688 6 8.1915 -4.958 9.5751 10 -6.5001 -7.1309 9.6489 10
% Label the band for each hole
text(xHole+.5, yHole, compose('%g', holeBand), 'Color', 'b')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Octave에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by