필터 지우기
필터 지우기

Angle between 2 lines

조회 수: 2 (최근 30일)
Elie
Elie 2014년 2월 19일
댓글: Jos (10584) 2014년 2월 24일
How can i calculate the angle between such two lines.is the dotvector method useful in such case?
line([50 50],[1 10000],'Color','G');
line([newBoxPolygon(1, 1) newBoxPolygon(4, 1)],[newBoxPolygon(1, 2) newBoxPolygon(4, 2)],'Color','G');
i tried this method
u=[newBoxPolygon(1, 1) newBoxPolygon(4, 1),newBoxPolygon(1, 2) newBoxPolygon(4, 2)]
v=[[50 50],[1 10000]]
CosTheta = dot(u,v)/(norm(u)*norm(v));
ThetaInDegrees = acos(CosTheta)*180/pi
but i'm getting an error can you please help
  댓글 수: 2
Jos (10584)
Jos (10584) 2014년 2월 19일
What is the exact error you're getting?
Elie
Elie 2014년 2월 19일
There is no logical or compiler error , the error is in the angel it self, because the angle between the 2 lines is less than that splitted by the function above

댓글을 달려면 로그인하십시오.

답변 (1개)

Jos (10584)
Jos (10584) 2014년 2월 19일
편집: Jos (10584) 2014년 2월 19일
You want to enter the direction vectors U and V into the formula
dU = [diffUx diffUy]
dV = [diffVx diffVy]
cosTheta = dot(dU,dV) ./ (norm(dU) * norm(dV))
  댓글 수: 4
Elie
Elie 2014년 2월 21일
Hey i tried your advice but im getting the following error "A and B must be same size" This is my code . what is the error
%Line1
x1=(newBoxPolygon(1, 1));y1=(newBoxPolygon(1, 2));
x2=[newBoxPolygon(1, 1) newBoxPolygon(4, 1)];y2=[newBoxPolygon(1, 2) newBoxPolygon(4, 2)];
%The theoritcal line
x1_1=1; x1_2=1000;
y1_1=900; y1_2=900;
dU = [(x2-x1) (y2-y1)];
dV = [(x1_2-x1_1) (y1_2-y1_1)];
cosTheta = dot(dU,dV) ./ (norm(dU) * norm(dV));
disp(cosTheta);
Jos (10584)
Jos (10584) 2014년 2월 24일
You are setting up the vectors the wrong way: the direction vectors dU and dV should be 2 element arrays. dU is, but dV is not.
If you remove the semi-colons you see what I mean.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by