Omnimaga

General Discussion => Other Discussions => Math and Science => Topic started by: fb39ca4 on January 01, 2011, 02:23:10 am

Title: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 01, 2011, 02:23:10 am
I want to understand the math behind 3d projection, but the wikipedia page left me ???
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: AngelFish on January 01, 2011, 02:49:52 am
Conceptually, 3d projection is pretty simple. Mathematically, it's a mess unless you cheat*.

Think of projection like a shadow (or a projector/camera :P). If you shine a light on something, it will leave a shadow on a flat, 2d surface that is what you would expect to see on a computer screen. So, in order to view the outline of something, all you have to do is draw straight lines from a point source (used for simplicity) through the object onto the screen, kind of like (http://upload.wikimedia.org/wikipedia/commons/4/48/Axonometric_projection.svg)

Wherever a line (known as a ray) passes "through" the screen, a pixel is drawn.

This method will only draw outlines though. If you want to draw the object itself, then another method known as raycasting works. Instead of a light source, you draw the rays from the user's eyes through a middle screen to points on the object. The intersection of the lines with the screen is where the pixels are turned on.

*By cheating, I mean doing anything other than modeling the scene in 3d. Many useful algorithms work around this.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 01, 2011, 05:25:18 am
Ah, so youre calculating the intersection of the line passing through the point and the camera with the screen, then.
Could you give some examples of cheating?
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: SirCmpwn on January 01, 2011, 08:30:42 am
I dont have an example of cheating, but if you go back a ways I have a TI-Basic implementation of 3D wireframe projection.  It's slow, but accurate.  The Wikipedia article on 3D projection is very useful.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: jnesselr on January 01, 2011, 04:29:24 pm
One way of cheating is using right triangles, but with 3D instead of 2D.  That way, you can use proportions.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: Builderboy on January 01, 2011, 05:50:27 pm
One way of cheating is using right triangles, but with 3D instead of 2D.  That way, you can use proportions.

Thats not cheating, thats using accurate math to get real projections of 3D points onto a 2D plane :)
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: jnesselr on January 01, 2011, 05:56:33 pm
One way of cheating is using right triangles, but with 3D instead of 2D.  That way, you can use proportions.

Thats not cheating, thats using accurate math to get real projections of 3D points onto a 2D plane :)
Then what do you consider cheating in this case?
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: Builderboy on January 01, 2011, 06:08:12 pm
Things like isometric displays, 1/2 point projection, raycasting, or anything else that does not give true 100% control 3D.  Be is as it may you can get quite realistic images through cheating (video games today still cheat on many things).  Basically as i see it, if you can view an object in 3D space and have complete control over rotation, translation, and scaling, you are working in true 3D.  Whenever you add constraints for the purpose of increasing speed, i see that as 'cheating' a little bit since its not true 100% 3D anymore.  Note that i don't mean cheating in a negative connotation :P Like i said, there is not a game out there on the market that does not cheat.  The only way (Imho) to not cheat in a full image render (with objects, reflections, light, texture, ect...) is to raytrace from the light sources, calculating the reflections and refractions, and calculating exactly how the human eye would perceive the scene.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 01, 2011, 07:50:09 pm
Dont you go backwards in ray tracing, so only the rays that hit the eye are shown?
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: Builderboy on January 01, 2011, 08:12:31 pm
Ah yes you are correct, its much more efficient that way XD
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 02, 2011, 08:07:19 pm
Anyways, getting back on track, can anyone give me a function, which takes the camera position, viewing angle, frustum, and a 3d point (x, y, z), and outputs the projection of that point on the screen in an (x, y) format?
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: SirCmpwn on January 02, 2011, 08:11:32 pm
Take a look at prgmRENDER in my TI-Basic 3D demo.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 03, 2011, 04:58:23 pm
Sorry, but could you give me a link? I couldnt find it by searching.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: Builderboy on January 04, 2011, 01:28:52 am
Here are the formulas i use:

Sx = S*(X/Z)
Sy = S*(Y/Z)

Where (X,Y,Z) is the coordinate of the point in 3D, S is the "size" of the screen, and (Sx,Sy) is the coordinates of the point on the screen.  To account for rotation, you would rotate the coordinates (X,Y,Z) before displaying them.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: willrandship on January 09, 2011, 06:51:48 pm
One of the coolest "Cheating" things I've heard of is bumpmapping. It makes objects look much more detailed than they are by having the lighting be different for different parts of the shape, making it look farther in or sticking out.
Title: Re: Can anyone explain the math behind 3d projection in english plz?
Post by: fb39ca4 on January 10, 2011, 12:56:20 pm
Now, there's tesselation, which is even better because you can get as many polygons as your graphics card can handle, giving you the same effect.
I just wanted to figure this out for a [possible] calc project, so theres probably not going to even be lighting.