#### Archived

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

# 3D Vector Mathematics

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

## Recommended Posts

I have a question... Given vector X and Direction D with a 60degree field of view, how can I determine if a vector P is within the field of view? -30 D +30 \ / / \ / / \ / / \ / / P? \ / / \ / / \X/ I am sure there is a simple solution to this but I am just getting started into 3D stuff... I bought 2 books on it but neither really seem to address this question like I would hope and I am not much of a math person so please bear with me... Thanks. Jumpster

##### Share on other sites
Ugh! It stripped out my spaces... Darn!

##### Share on other sites
You can calculate the angle between two vectors with
angle = arccos(v1*v2/sqrt((v1.x^2 + v1.y^2 + v1.z^2)*(v2.x^2 + v2.y^2 + v2.z^2)))

where v1*v2 = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z

So the angle between D and X must be less than 30°. But then you''ve got a circular field of view.

If you want to have a rectangular field of view, you have to project V=X-D onto the upvector U (you should have given) and the "right vector" R = D x U.
D x U means the cross product of D and U:
R.x = D.y*U.z - D.z*U.y
R.y = D.z*U.x - D.x*U.z
R.z = D.x*U.y - D.y*U.x

The cross product v1 x v2 gives a vector perpendicular to v1 and v2. The amount of the cross product is equal to the area of the parallelogramm made by v1 and v2.

To project V on U, calculate VU = (U*V)*U, to project V on R VR = (R*V)*R.
Now you can "convert" the vectors back to viewpoint coords:

XU = D + VU
XR = D + VR

Usually the field of view angle (fov) is given vertically,
so you can test if the angle between D and XU is less than 30°. Then multiply fov by the aspect ratio of the viewing rectangle and test if the angle between XR and D is less than fov*aspect/2.

GA

##### Share on other sites
This is wonderful. Thanks for the detailed explaination...

I have a good understanding of what you are saying but I am still a tad-bit confused. For example: you said I should have supplied an upvector...? I thought that would be implied with the direction vector? or am I totally clueless?

Also, I am assuming that the values D and X in your explanation were in place in response to my question. Where did v1 and v2 come from or is that just to illustrate a general formula? If that''s the case, which values would I place into it arcos( (X*D) etc...) or arcos( (X*P) etc...) where P = point vector that I am testing for...

Again, sorry if I am clueless, but I am just trying to learn this stuff.

Thanks for you time, I know it''s valuable...
Jumpster

##### Share on other sites
The upvector is not implied with the direction vector. You can imagine easily the camera rotating around the direction vector.

Substitute v1 and v2 with the two vectors you need the angle between. Sorry, I think I swapped P and X in my explanation. I don''t need (your) X which I think is the camera position. D is the lookat vector and (my) X is the vector from the camera position to the vertex P which should be examined.

GA

• 10
• 13
• 52
• 11
• 15