Projection of a sphere..

Started by
8 comments, last by iMalc 18 years, 8 months ago
Hello, When you project a sphere to the screen you will get a circle. The center of the circle will be the projected center of the sphere. What I'm looking for is a nice and clean way to calculate the radius, in projected space, of the circle given the radius, in world space, of the sphere. I have a D3D-compliant projection matrix available. Also, as a side question, does anyone know an efficient way to software rasterize a circle? I need this for my occlusion culling system to be able to cull bounding spheres instead of only bounding boxes. - Kasper
Advertisement
Quote:Original post by Kasper Fauerby
When you project a sphere to the screen you will get a circle.


i dont know about you, but i dont.

consequently, rasterizing them is rather hard.
I agree with Eelco. Perspective projection distorts things as they get furthur from the centre, so projecting a sphere onto a flat plane does not often give a perfect circle. Only when the origin of the sphere is in the exact center of the projection area will it be a circle.

Unless of course you're doing orthographic or isometric projection...
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
just roughly,

tan(FOVy / 2) = Y / Z

Y = tan(FOVy / 2) * Z

Everything is better with Metal.

Hmm, ok thanks. I hadn't really thought about that :) I'm aware that a perspective projection "skews" things by mapping from a pyramid shape into a box but I had still thought that the projection of a sphere would form a circle. Now I can see that it will often be somewhat elliptic.

In my case however it's not that important that I get the *exact* projection of the sphere - what I need is simply the bounding circle of the projection of the sphere.

@Oliii: I'm sorry, but I didn't quite catch that. Could you perhaps elaborate a bit on what you wrote earlier? As I wrote above a rough (preferably conservative) estimate is fine for me.

Also I'm still interested in fast ways to rasterize perfect circles!

Thanks for reading,
- Kasper
Well you could unproject 2 points, world space center and world space center+world space radius (always on the vertical axis) and then take the screen space distance between the two. I havn't given it much thought but it seems like that would work for calculating a screen space bounding volume of a sphere.

- Dan
Quote:Original post by Kasper Fauerby
Hmm, ok thanks. I hadn't really thought about that :) I'm aware that a perspective projection "skews" things by mapping from a pyramid shape into a box but I had still thought that the projection of a sphere would form a circle. Now I can see that it will often be somewhat elliptic.

In my case however it's not that important that I get the *exact* projection of the sphere - what I need is simply the bounding circle of the projection of the sphere.

@Oliii: I'm sorry, but I didn't quite catch that. Could you perhaps elaborate a bit on what you wrote earlier? As I wrote above a rough (preferably conservative) estimate is fine for me.

Also I'm still interested in fast ways to rasterize perfect circles!

Thanks for reading,
- Kasper


ok, ....

Z is the distance of the sphere centre to the camera position. Or the Z value once transformed through the perspective transform matrix.

Y, well, that would be the radius.

so, ... what Am I talking about??!? [lol]

OK, let's try again....

you have near_plane, where stuff is rendered.

you have the z-coord of the sphere centre.

you have the radius of 'R' the sphere at that Z distance.

you want 'r', the size of the sphere at near plane.

so

r / near = R / z

=> r = (R / z) * near

alternatively, you can do like dgreen said, which is a method I used for debugging spheres, whithout having to render complicated 3D spheres or wireframes (clutter).

Get two diametrically opposed points on the spheres, project them on the near plane, get their distance, Bob's your uncle.

As for me, I took the point at the centre of the sphere, and a point at distance 'radius' to the centre, and along the Up vector of my camera. Therefore, ensuring the point was giving the right perspective when projected.

BTW, I rendered my spheres as a list of segments (32 to be exact). That would be an easy way to rasterise the sphere.

Else, look for the bresendham algorithm, which as a sphere algorithm (as well as segment drawing).

Everything is better with Metal.

this is not true that a prospective projection of a sphere would not give a circle it in screen space. consider an arbitraty sphere with center p and radius r. now consider the viewscreen x alligned we have the extremems of the sphere at (px, y) = center (px + r, y), and (px - r, y) the distance bw the center and and the extremes is r in world space and it's (r/u)*D where D is the distacne from viewplane to eye. the only reason it would be elipse in screen space is because of incorrect aspect ratios. the only


Tim
timw: I suggest you render a sphere with perspective projection and find out. A circle that divides the sphere along a plane parallel to the screen is indeed projected as a circle, but it doesn't describe the outline of the rendered shape. The part of the sphere that's in front of this circle extends outwards (away from the center of the projection) and the part behind extends inwards, just due to perspective. Even when the sphere is aligned to the center of the projection, a circle that bisects it through the center isn't the correct outline... Think "horizon".
Quote:Original post by timw
this is not true that a prospective projection of a sphere would not give a circle it in screen space. consider an arbitraty sphere with center p and radius r. now consider the viewscreen x alligned we have the extremems of the sphere at (px, y) = center (px + r, y), and (px - r, y) the distance bw the center and and the extremes is r in world space and it's (r/u)*D where D is the distacne from viewplane to eye. the only reason it would be elipse in screen space is because of incorrect aspect ratios. the only

Tim
If that is your opinion then you don't know half as much as you think you do!
We ARE talking about with a perfect 1:1 aspect ratio, and you are NOT always going to get a perfect circle.
Just render a largeish sphere close to the camera, and in the corner of the viewing area yourself so that you can see how wrong you are (In fact if you increase the FOV, it exaggerates the effect). Then come back here apologising and begging for someone to explain why it really is that way.

Next time just politely say that you THINK we're incorrect, and we'll happily put you straight.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement