-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintTarget.m
More file actions
35 lines (28 loc) · 855 Bytes
/
printTarget.m
File metadata and controls
35 lines (28 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
% S? l??ng ?i?m c?n l?y
numPoints = 15;
% Kh?i t?o m?ng l?u tr? t?a ?? c?a các ?i?m
points = zeros(numPoints, 2);
% L?y ng?u nhiên t?a ?? x và y cho t?ng ?i?m
for i = 1:numPoints
while true
x = randi([15 45]);
y = randi([15 45]);
% Tính kho?ng cách t? ?i?m hi?n t?i ??n các ?i?m ?ã l?y tr??c ?ó
distances = sqrt(sum((points(1:i-1, :) - [x, y]).^2, 2));
% Ki?m tra ?i?u ki?n v? kho?ng cách
if ~any(distances < 3) && all(distances > 4)
points(i, :) = [x, y];
break;
end
end
end
% Hi?n th? t?a ?? c?a các ?i?m
disp(points);
% V? các ?i?m lên ?? th?
plot(points(:, 1), points(:, 2), 'o');
axis([10 50 10 50]); % ??t gi?i h?n tr?c x và y
% ??t nhãn cho tr?c x và y
xlabel('X');
ylabel('Y');
% ??t tiêu ?? cho ?? th?
title('V? các ?i?m ng?u nhiên');