Calculating angles between two points in 3D that is measured from positive x-direction

조회 수: 15 (최근 30일)
I have multiple points that I need to calculate the angle between two points that respects to x-direction as shown in the image. The angle is measured from positive x direction (counter clockwise).
For 2D case as shown in the image:
% N is number of points
for j=1:N-1
for k=(j+1):N
% difference distance in x-direction
sepx=X(1,k)-X(1,j);
sepy=Y(1,k)-Y(1,j);
r = sqrt(sepx^2+sepy^2);
% use atan2d to return angle in degree between -180 to 180.
% use mod to return angle in degree between 0-360
theta=mod(atan2d(sepy,sepx),360);
end
end
For 3D case, I only changed this part
sepx=X(1,k)-X(1,j);
sepy=Y(1,k)-Y(1,j);
sepz=Z(1,k)-Z(1,j);
r = sqrt(sepx^2+sepy^2 +sepz^2);
theta=mod(atan2d(sepy,sepx),360);
I am really bad at 3D in term of visualization to project thing. Is that correct to find angle of two points in 3D that is measured from positive x-direction (counter clockwise). The counter clockwise for an observer looking from above on the xy-plane. Please helps. Thanks.
  댓글 수: 6
Laura
Laura 2016년 5월 3일
the distance r needs to have Z components in there right?

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

채택된 답변

Image Analyst
Image Analyst 2016년 5월 4일
편집: Image Analyst 2016년 5월 4일
I thought you had (x,y,z) coordinates for all three points? If not, do you have the points in spherical coordinates like radius theta, and phi? If you have x,y,z, just use x and y, ignoring z and then use the dot product or whatever the 2D angle formula is, like this: https://www.google.com/?gws_rd=ssl#q=angle+between+two+2d+vectors
  댓글 수: 1
Laura
Laura 2016년 5월 16일
I have 512 spheres that has (x,y,z) coordinates. I want to project all 512 points on the xy-plane. Do I just use x and y?

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by