# Range of atan2, confusion when using coordinates of a photo

2 visualizzazioni (ultimi 30 giorni)
HecLondon il 24 Set 2013
I have some points in a black and white image. I have the coordinates, x,y, of the centroids and I want to order them clockwise. To do these I want to use the angles. However I have a big confusion: I'm assuming that the axis of coordinates of atan2 are in the center of my photo. Then, I'm using one of the points as an offset to make the zero angle there.
Am I completely confused about this? Is this so difficult to achieve? I just want to get the angles of all the points, the angle zero being a point I choose, and then use the angles to order the centroids in a clockwise direction (incresing angle direction).
I hope I can solve this problem with your help! Many thanks, Hector
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

W. Owen Brimijoin il 24 Set 2013
You'll need to subtract the XY centre of your image from the points before you measure the angle using atan2. The following code might help clear things up a bit:
%this is the center of the image
image_center_xy = [.5 .5];
%here are some random points:
x = rand(10,1); y = rand(10,1);
%plot the points:
scatter(x,y);hold on
axis([0 1 0 1])
%pick a point with the mouse
[X,Y] = ginput(1);
%find the distances between click and the data:
distances = sqrt((x-X).^2 + (y-Y).^2);
%find the closest point to to the mouse click:
point0idx = find(distances == min(distances));
%replot the chosen point as a filled circle:
scatter(x(point0idx),y(point0idx),'filled');
%compute angles:
angles = -atan2(y-image_center_xy(2),x-image_center_xy(1));
%make the chosen point an angle of zero (and use modulo for folded angles):
angles = mod(angles - angles(point0idx),2*pi);
%sort by angle:
[angles, idx] = sort(angles);
%sort everything by the angle index:
x = x(idx); y = y(idx);
%plot the line of the ordered points:
plot(x,y,'r'); hold off
Did I understand your question correctly?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Images in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by