How to calculate a angle between two vectors in 3D

Technical Source
2 min readJan 15, 2024

--

Hi, I have a question, I have a table with 12 reference points

if true
% POINT X Y Z
1 0 0 0
2 70.5 0 0
3 141 0 0
4 141 0 141.5
5 70.5 0 141.5
6 0 0 141.5
7 0 137.5 0
8 70.5 137.5 0
9 141 140 0
10 141 141.5 141.5
11 70.5 139 141.5
12 0 141.5 141.5
end

The segment 1 is defined by the point 1 and point 2 and the segment 2 is defined by the point 1 and point 7. I am able to calculate the angle with the following rotine,

if true
% angle_x1_x13 = atan2(norm(cross(v1,v2)),dot(v1,v2));
anglout = radtodeg(angle_x1_x13);
end

The result is ~90º and this result is correct if I think in xy plan, but I need to calculate the angle to yz plan and xz plan. Anyone help me?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

This code uses your angle calculation and shows for different reference points (3d). 2d is the same for your formula.

% Origin is reference point
p1 = 1*ones(1,3); % directly v1 = p1
p2 = 2*ones(1,3); % directly v2 = p2
% With origin as the reference point, the angle between vectors is 0
ang = rad2deg(atan2(norm(cross(p1,p2)),dot(p1,p2)));
disp(ang)
% Choosing reference point such that new v1, v2 are at 90 degrees
refpoint = [2 2 1];

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet