matlab - Angle calculation in 3D space -


i have end points 2 two lines , need find angle between these 2 lines.

similarly have 60 such points in excel sheet, , need find angles between lines joining these 60 points. need find angle between these line segments.

i want in matlab :

d = xlsread('45_a.xls'); costheta = dot(d(i,:),d(i+1,:))/(norm(d(i,:))*norm(d(i+1,:))); xlswrite('45_aav',costheta); 

this program had written repeat 60 values in excel sheet, i.e., had put in loop. wrong values being calculated, i.e., angle values in imaginary , real values written in excel sheet.. think there problem calculation part. can please ?

the angle in degrees between 2 vectors u , v can computed as

180/pi*acos(dot(u,v)/(norm(u)*norm(v))) 

i tested on following randomly generated set of 60 vectors, following formula:

d = (10*rand(60,3)-5);    % random matrix 60 3 i=1:size(d,1)-1      angleindegrees = 180/pi*acos(dot(d(i,:),d(i+1,:))/(norm(d(i,:))*norm(d(i+1,:))));     disp(angleindegrees); end 

no imaginary values obtained.

the above assumes vectors contained in d ones between want find angles. if array have contains points p, , want find angles between lines connecting these points, first need subtract coordinates of adjacent points. this:

points = (10*rand(60,3)-5);   % random matrix 60 3 d = diff(points,1);           % differences between consecutive rows 

and rest above.


Comments