Phúc Lê
Phúc Lê

Reputation: 2635

Generate coordinate points with circle pattern points in Octave

Two types of samples with circle pattern

I want to generate 300 samples of both types, red and blue, of coordinate points with these patterns. Using rand() for x and then calculate y using Pythagorean theorem doesn't help because for the same x, we can have different y.

Upvotes: 1

Views: 633

Answers (1)

m7913d
m7913d

Reputation: 11064

As suggested by Luis Mendo, you can use the typical rand function of matlab to generate random points in polar coordinates as follows:

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

enter image description here

Upvotes: 2

Related Questions