# Frustum Centre

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

## Recommended Posts

Douse anyone know the best way to get the centre point of a frustum. I am attempting to build a sphere around the frustum but I am not having much luck. Ideally I want the algorithm to work purely on the frustum plains. Otherwise I need to keep passing in camera details. However I will take anything that works for the time being. Thanks in advance.

##### Share on other sites
You can construct a sphere through four points. If you take the midpoints between all top and bottom points (i.e. for the front plane take the top left and bottom left and average, etc) the sphere should be good enough in capturing the frustum I think.

Here is more specific sphere code for frusta. I haven't read this precisely but it seems ok for you.

Greetz,

Illco

##### Share on other sites
Ok I have the centre now, By tweaking the target vector of the camera so its always in the centre. This way I only have to calculate it once.

Just need a good way to find the radios!

##### Share on other sites
Thanks but your "sphere through four points" link , although may work its far to computational to even try. There simply must be a better way.

Also I have looked at your second link but its not going to work in my frustum as my centre is in world space and his is at 0,0. I could go down that road but I don’t have a “LookVector” function.

That link is pretty much the only one on the net. I could really use a second view on the subject.

##### Share on other sites
Having now closely inspected the code found on your link I can say it will not provide a correct bounding sphere. As you will see by the diagram on that subject the sphere will cut of the far corners. If you read the code carefully you will see this will be a problem the bigger the frustum gets.

I may be incorrect, but I don’t think so.

All I need now is just 1 world space vector for one of the frustum corners.

Surly someone else must have done this before me,!!!

##### Share on other sites
There is an exact solution. You get the distance to the center of the sphere (z) by solving this equation for z:

(z - n)2 + dn2 = (f - z)2 + df2

z = distance to the center of the sphere
n = distance to the near plane
dn = half the diagonal of the near plane
f = distance to the far plane
df = half the diagonal of the far plane

z = (f2 - n2 + df2 - dn2) / 2(f - n)

The radius of the sphere is:

r = sqrt((z - n)2 + dn2)

BTW,

dn = sqrt(1 + a2) * n * tan(fov/2)
df = sqrt(1 + a2) * f * tan(fov/2)
a = aspect ratio

##### Share on other sites
JohnBolton thanks for the algorithm.
It is exactly what I am after.
However I can’t seem to make it work

Using the values

a = 1
n = 4.6
f = 10.6
dn = sqr(1 + a^2) * n * tan((3.14 / 4) / 2) = 2.69310043112487
df = sqr(1 + a^2) * f * tan((3.14 / 4) / 2) = 6.20584012389643

I agree this is correct.

But

z = ((f^2 - n^2) + (df^2 - dn^2)) / (2*(f - n)) = 10.2049718092698

And that’s not correct it should be 9.2 ish

Then
r = sqr((z - n)^2 + dn^2) = 6.21840002853101

should be exactly 5 ish

Now if z was correct then r would be correct.

So basically why is my z not working out correctly?

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013418
×