# Projection of a sphere..

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

## Recommended Posts

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

##### Share on other sites
Quote:
 Original post by Kasper FauerbyWhen 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.

##### Share on other sites
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...

##### Share on other sites
just roughly,

tan(FOVy / 2) = Y / Z

Y = tan(FOVy / 2) * Z

##### Share on other sites
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!

- Kasper

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by Kasper FauerbyHmm, 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).

##### Share on other sites
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

##### Share on other sites
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".

##### Share on other sites
Quote:
 Original post by timwthis 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634074
• Total Posts
3015345
×