# Angle Comparison

2 views (last 30 days)

Show older comments

##### 0 Comments

### Answers (1)

Jonathan
on 21 Nov 2011

If I understand this setup correctly, then the following is true. Take a line segment (I take this to be what you mean by side) perpendicular to the floor and tilt it 30 degrees to the right (from the observers position). Then the angle in question is 60 degrees. Now rotate the camera (observer) 90 degrees is either direction. The angle in question is now 90 degrees.

With this understanding, I have a solution that involves a projection based on the camera position. Suppose the base of the line segment is at (0, 0, 0), the other end of the segment is at S = (Sx, Sy, Sz), and the camera is at C = (Cx, Cy, 0). First, make S and C unit vectors by element-wise dividing by the respective norm. Project S onto the plane perpendicular to C via SP = S - S*C.C (where * is the dot product and . is the scalar product). Now, you need to find the line of intersection between the XY-plane and the plane perpendicular to C. Take the reference line R = C x (0, 0, 1) (where x is the cross product). Find the angle between the lines via SP * R = norm(SP) . norm® . cos(theta) (where theta is the angle between the lines). You may need to take the supplementary angle to theta if theta is greater than 90 degree.

Example:

S = [1,1,1];

C = [0,1,0];

SP = S - dot(S,C)*C;

R = cross(C, [0,0,1]);

theta = acosd(dot(SP, R)/(norm(SP) * norm(R)));

if theta > 90, then theta = 180 - theta; end

disp(theta)

To get the second angle, rotate C about the z-axis the desires number of degrees (see Rotation Matrix for details).

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!