directions from cartesian xy coordinate pairs
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am trying to work out directions from cartesian coordinate pairs
My data is below. I have (x,y) starting positions and (x,y) finishing position coordinates and I am trying to work out which cardinal direction axis they are moving towards given that xc and yc are the middle of the 'world'.
The data set of interest below are data2, I have applied various transfomrations that don't matter too much. What is clear is that the starting position is always near the cnetre of the screen and moves away generally along one cardinal. I just need to know where elegantly. I can see the first one goes up, second one right and third one left. How do I calculate this?
data = [502.1,354.9,512.5,151.9;
517.2,366.8,707.3,365.4;
508.3,374.1,293.8,368.9;
519.9,378.4,726.8,349.6;
499.5,362.2,726.7,356.4;
498.4,371.3,707.4,335.3;
492.3,362.3,494.6,149.8;
518.1,377.7,533.7,160.7;
504.7,372.3,509.6,180.7;]
xc = 512;
yc = 384;
data2 = [];
for i = 1:length(data)
x1 = (data(i,1)-xc)/26
y1 = (yc-data(i,2))/26
x2 = (data(i,3)-xc)/26
y2 = (yc-data(i,4))/26
data2 = [data2; x1 y1 x2 y2]
slope(i) = y2-y1/x2-x1
end
0 commentaires
Réponses (1)
David Young
le 30 Août 2011
Have a look at the atan2 function. I suspect that xc and yc and the factor of 26 are irrelevant, and you just need something like
heading = atan2(y2-y1, x2-x1);
The result will be in radians. You can convert to degrees if you wish to.
It is very worthwhile to plot out some of the positions by hand on a sheet of graph paper, measure the directions with a protractor, and compare this with the results you get, so that you can be confident about which direction has heading 0 and whether the heading increases clockwise or anticlockwise (counterclockwise).
0 commentaires
Voir également
Catégories
En savoir plus sur Polar Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!