Author Topic: Can anyone explain the math behind 3d projection in english plz?  (Read 10582 times)

0 Members and 1 Guest are viewing this topic.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
I want to understand the math behind 3d projection, but the wikipedia page left me ???

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #1 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

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.
« Last Edit: January 01, 2011, 02:51:25 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #2 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?

SirCmpwn

  • Guest
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #3 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.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #4 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.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #5 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 :)

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #6 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?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #7 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.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #8 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?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #9 on: January 01, 2011, 08:12:31 pm »
Ah yes you are correct, its much more efficient that way XD

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #10 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?

SirCmpwn

  • Guest
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #11 on: January 02, 2011, 08:11:32 pm »
Take a look at prgmRENDER in my TI-Basic 3D demo.

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #12 on: January 03, 2011, 04:58:23 pm »
Sorry, but could you give me a link? I couldnt find it by searching.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #13 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.

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Can anyone explain the math behind 3d projection in english plz?
« Reply #14 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.