0

I have two unitary vectors P and Q in Cartesian coordinates. I need a very fast way to know if the angle between then is smaller than a certain amount A. The best way I could think of is:

if(acos(dot(P, Q)) < A)
    cull();
else
    draw();

or, conversely:

if(dot(P, Q) > cos(A))
    cull();
else
    draw();

for the bigger the angle, smaller its cosine. It is for a culling algorithm. The object won't be drawn if the angle is smaller than A (out of the field of vision), so, a small amount of false negative is acceptable (I can occasionally send to GPU something out of the field of view), But false positive is not (I can't refrain from rendering something inside the field of view).

What is the fastest way to do this? Can I get any better than I am already doing?

lvella
  • 12,754
  • 11
  • 54
  • 106
  • 2
    Certainly if `A` is a constant that defines the FOV, you can precompute its cosine and use the second method, which would then be very fast? – jrsala Nov 16 '14 at 16:41
  • A is not constant. My space is spheric, A is the sum of the radius of the object with the radius of each "plane" limiting the field of view (5, in total). A "plane" in a spherical space is a "big sphere". The far clipping plane is an exception, for it is not a "big sphere", its radius is smaller. Summarizing: for each object in the scene I have 2 different `A`, and they change if the object changes size. – lvella Nov 16 '14 at 17:09
  • You could use a look up table for cos(A) say precompute it for 1˚, 2˚, etc then use `cosA = table[floor(A*180/pi)]; if(dot(P,Q) > cosA) ...`. (Or possibly ceil(...).) – Salix alba Nov 16 '14 at 21:26
  • How exactly does A depend on object size? Does object change it's size instantly? – MBo Nov 17 '14 at 07:26
  • For now, there is just one object in the scene that grows. And `A=R-r` where `r` is the radius of the object's bounding sphere, and R is the radius of the field of view of the limiting sphere. But you may ask: what spheres' radius has to do with the angles in the question you asked? I omitted that explanation from the question because it is complicated and didn't seem relevant, but briefly, as I said before, the spheres are contained in a spheric space, so every "strait" line there (like a radius) is an arc on a bigger hypersphere. Think of earth meridians and tropics: equator radius is pi/2. – lvella Nov 17 '14 at 16:45

0 Answers0