Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Generateing a number of points in 2D

Subject: Generateing a number of points in 2D

From: HU Jianho

Date: 16 May, 2012 12:46:09

Message: 1 of 3

Hi there,
I would like to generate a cluster of points around the zero in two dimention. For example if I want to generate 10 points locating the first point at the zero then the points will be as following:
[0 0]
[1 0]
[0 1]
[-1 0]
[0 -1]
[1 1]
[-1 1]
[-1 -1]
[1 -1]
[2 0]
I want a function do that even the number of points is changed and also I want the distributing process be in same direction (clockwise or anticlockwise).

Any help will be appreciated.

Subject: Generateing a number of points in 2D

From: Roger Stafford

Date: 16 May, 2012 20:11:14

Message: 2 of 3

"HU Jianho" wrote in message <jp07ig$hcv$1@newscl01ah.mathworks.com>...
> Hi there,
> I would like to generate a cluster of points around the zero in two dimention. For example if I want to generate 10 points locating the first point at the zero then the points will be as following:
> [0 0]
> [1 0]
> [0 1]
> [-1 0]
> [0 -1]
> [1 1]
> [-1 1]
> [-1 -1]
> [1 -1]
> [2 0]
> I want a function do that even the number of points is changed and also I want the distributing process be in same direction (clockwise or anticlockwise).
>
> Any help will be appreciated.
- - - - - - - - - -
  Let N be the desired number of points.

 n = ceil(sqrt(N/3));
 [X,Y] = ndgrid(-n:n);
 [~,q] = sortrows([X(:).^2+Y(:).^2,mod(atan2(Y(:),X(:)),2*pi)],[1 2]);
 P = [X(q(1:N)),Y(q(1:N))];

Roger Stafford

Subject: Generateing a number of points in 2D

From: HU Jianho

Date: 17 May, 2012 10:12:07

Message: 3 of 3

"Roger Stafford" wrote in message <jp11l2$je7$1@newscl01ah.mathworks.com>...
> "HU Jianho" wrote in message <jp07ig$hcv$1@newscl01ah.mathworks.com>...
> > Hi there,
> > I would like to generate a cluster of points around the zero in two dimention. For example if I want to generate 10 points locating the first point at the zero then the points will be as following:
> > [0 0]
> > [1 0]
> > [0 1]
> > [-1 0]
> > [0 -1]
> > [1 1]
> > [-1 1]
> > [-1 -1]
> > [1 -1]
> > [2 0]
> > I want a function do that even the number of points is changed and also I want the distributing process be in same direction (clockwise or anticlockwise).
> >
> > Any help will be appreciated.
> - - - - - - - - - -
> Let N be the desired number of points.
>
> n = ceil(sqrt(N/3));
> [X,Y] = ndgrid(-n:n);
> [~,q] = sortrows([X(:).^2+Y(:).^2,mod(atan2(Y(:),X(:)),2*pi)],[1 2]);
> P = [X(q(1:N)),Y(q(1:N))];
>
> Roger Stafford

Many thanks Roger, that exactly what I want.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us