Octave中用圆形图案点生成坐标点

Generate coordinate points with circle pattern points in Octave

我想生成 300 个具有这些图案的坐标点样本,包括红色和蓝色两种类型。 对 x 使用 rand() 然后使用勾股定理计算 y 没有帮助,因为对于相同的 x,我们可以有不同的 y。

根据 Luis Mendo 的建议,您可以使用典型的 matlab rand 函数在 polar coordinates 中生成随机点,如下所示:

figure
hold on

red = sampleCircle([1.4 1.6], 300);
plot(red(:, 1), red(:, 2), 'r*');

blue = sampleCircle([0 0.5], 300);
plot(blue(:, 1), blue(:, 2), 'b*');

function X = sampleCircle(rangeR, n)
  r = rand(n, 1) * diff(rangeR) + rangeR(1);
  theta = rand(n, 1) * 2*pi;

  X = r .* [cos(theta) sin(theta)];
end