#### Archived

This topic is now archived and is closed to further replies.

# Calculating direction angle

This topic is 5263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I have two vectors: the direction vector (vector from eye point to lookat point), and vector from eye point to a point on the leftmost of the screen. How to calculate the angle between them? Is a camera field of view angle covers the width or the height of the screen? Cause a monitor''s width is longer than its height. Thanks very much.

##### Share on other sites
I wrote this C# function to find the axis-angle matrix between two vectors. You can just use the angle part if that''s all you need, and you can probably adapt it to any language without much effort.

public Matrix AxisAngle(Vector3 v1, Vector3 v2){	Vector3 nv1 = Vector3.Normalize(v1);	Vector3 nv2 = Vector3.Normalize(v2);	float angle = (float)System.Math.Acos((double)Vector3.Dot(nv1,nv2));	Vector3 axis = Vector3.Normalize(Vector3.Cross(nv1,nv2));	return Matrix.RotationAxis(axis, angle);}

##### Share on other sites

Sorry, I didn''t put my question correctly. I already know how to calculate the angle between two vectors.

All I want to ask now is how to find the vector from the eye point to a point on the leftmost of the screen.
I had tried to Unproject the point (0, viewport.width / 2, 1), into world space. Then I subtract this point with my eye point to get the vector.

But the result is not quite right, cause the angle is changing all the time, which I think it should be always the same.

Is my way to calculate the angle correct? Or is my vector calculation correct?

##### Share on other sites
There''s actually an infinite number of 3d positions belonging to the 2d left border of the screen... They all belong to your frustrum''s left plane. Now, if you want the leftmost points on screen aligned on the horizon then they all belong to the line parralel to the above plane and going trough the eye position. I think what you are looking for is more like a definition of fov.

X /|s p
^ / |c l
| / |r a
eye->Z|e n
\ |e e
\ |n .
\|z = zoom

Usually the left plane of your frustrum (left border of the screen) intersect the screen plane (Z=zoom) at coordinate X=-1.
Given this property and provided you build your frustrum this way
one of the points you are looking for would be (-1,0,zoom) in camera space.

I hope you can derive useful stuff from that...
Of course the upper and bottom plane intersect on coordinate Y=aspect_ratio of display (ie: height/width), so yes, usually the fov covers the width of the screen but nothing force you to do it that way.

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007154

×