determining angles

5 views (last 30 days)
Jules Ray
Jules Ray on 30 Oct 2011
dear colleagues:
i'm dealing with a confusing problem related with rectangle geometry. The problem is the next:
i got a regular rectangle defined by 4 coordinate pairs (UTM coordinates) defined as Z:
Z=
700438,401000000 6015652,08900000
701016,755000000 6016378,41000000
701096,612000000 6016314,82200000
700518,259000000 6015588,50000000
the problem is: i need to obtain the angle of the longest side of the rectangle. I have prepared a script to obtain the length of the longest side but i dont know how to obtain the angle.
this the script to obtain the length of the longest side of the rectangle:
X=Z(:,1);
Y=Z(:,2);
%Define coordinates for each vertice
x1=Z(1,1);
x2=Z(2,1);
x3=Z(3,1);
x4=Z(4,1);
y1=Z(1,2);
y2=Z(2,2);
y3=Z(3,2);
y4=Z(4,2);
%minimum and maximum for the entire dataset
minx=min(X);
miny=min(Y);
maxx=max(X);
maxy=max(Y);
nim=numel(Z);
% LENGHT
%Alternative 1, calculate all diagonals, the middle value one should be the
%lenght
A=sqrt((x2-x1)^2+(y2-y1)^2);
B=sqrt((x3-x2)^2+(y3-y2)^2);
C=sqrt((x3-x4)^2+(y3-y4)^2);
D=sqrt((x4-x2)^2+(y4-y2)^2);
E=sqrt((x3-x1)^2+(y3-y1)^2);
F=sqrt((x4-x1)^2+(y4-y1)^2);
G=sqrt((x3-x1)^2+(y3-y1)^2);
V=[A B C D E F G];
W=sort(V);
S=W'; %max to min ordering of obtained results and transposing
H=round(S); %eliminate decimal places
minV=min(H); % find min value in H
H(H==minV)=0; % set all min values to zero
maxV=max(H); % find max value in H
H(H==maxV)=0; % set all max values to zero
%intermediate=H(H~=0); %matrix with non-zero values, max and min values %eliminated
ind=find(H~=0, 1, 'first'); %finds the address of the first non-zero value
ddg=H(ind); %lenght of the longest side of the rectangle "Requested answer"
if someone have an idea ¿how to obtain the azimut or angle of the longest side of the rectangle?
thanks for your time...

Answers (1)

Sven
Sven on 31 Oct 2011
I have no experience with UTM coordinates and whether you're dealing with geometry on a curved surface, but if as you state, it's simple rectangle geometry, then any 3 points of that rectangle define a right-angled triangle.
% Choose any 3 points of the rectangle
p1 = [80 20];
p2 = [30 40];
p3 = [30 20];
% Make vectors along each edge of the triangle
v12 = p2-p1;
v13 = p3-p1;
v23 = p3-p2;
% Normalise those vectors
u12 = v12/norm(v12);
u13 = v13/norm(v13);
u23 = v23/norm(v23);
% Compute angles as the acos of their dot products
angle1 = acos(dot(u12, u13, 2));
angle2 = acos(dot(u23, -u12, 2));
angle3 = pi - angle1 - angle2;
% Display
figure, plot(p1(1),p1(2),'b.',p2(1),p2(2),'g.',p3(1),p3(2),'m.'), axis equal, hold on
text(p1(1),p1(2),sprintf('Pt1 (%d deg)',round(angle1/pi*180)))
text(p2(1),p2(2),sprintf('Pt2 (%d deg)',round(angle2/pi*180)))
text(p3(1),p3(2),sprintf('Pt3 (%d deg)',round(angle3/pi*180)))

Tags

Products

Community Treasure Hunt

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

Start Hunting!