Live data from Hacker News

Introduction to the Math of Computer Graphics

codeofthedamned.com

11–20 of 35 posts

Re: Introduction to the Math of Computer Graphics

#11
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

Matrices are a way of accumulating a bunch of separate transformations you might want to perform on a point (in the lingo, points are vectors because each coordinate of the point is an element of the vector).

Suppose figuring out where a world point (in a game map, for example) should show up on screen (in pixels) looked like a bit like this function call sequence (this is simplified):

    screenPoint = perspective(move(rotate(move(worldPoint))))
Think of a camera moving around the world; in virtual reality, this is exactly equivalent to the camera staying put and the world moving around instead. That's more or less how 3D graphics works. You have a virtual box that logically lives behind your screen, with the same x and y coordinates as your screen resolution, and z coordinates handled by a Z buffer that's used to determine what overlaps what. A big chunk of the matrix work is about moving, rotating and squishing the whole virtual world until the bit you want to look at fits into the virtual box that lives behind the screen.

Each function (perspective, move (aka translate), rotate, scale, etc.) can be expressed in the form of multiplication by a matrix. See [1], for example. That turns it into something like this:

    screenPoint = perspectiveMatrix * moveMatrix * rotateMatrix * moveMatrix * worldPoint
But because matrix multiplication is associative, we can calculate a single matrix to do all the work:

    transformMatrix = perspectiveMatrix * moveMatrix * rotateMatrix * moveMatrix
    screenPoint = transformMatrix * worldPoint
And this is much more efficient because there's fewer calculations that need to be performed per point.

[1] https://en.wikipedia.org/wiki/Rotation_matrix

Re: Introduction to the Math of Computer Graphics

#12
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

Yeah, while being informative the article is not necessarily inspiring. I just gives a rundown of linear algebra without talking about how it relates to the graphics.

Re: Introduction to the Math of Computer Graphics

#13
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

My intention with this first post was to show how to work with the mathematical constructs.

I have already started on the next article, which will provide the context for what these mathematical constructs provide.

To briefly answer your question, for 3d graphics the Matrix provides an efficient mechanism to translate, scale, rotate, shear and convert between different coordinate systems.

Re: Introduction to the Math of Computer Graphics

#14
post #7
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

Check out this article! http://www.senocular.com/flash/tutorials/transformmatrix/ It helped me understand them quickly, with easy to understand, practical examples. Don't mind the "Flash 8" context, there really isn't anything flash-specific in there.

That's a helpful site, especially the interactive examples. Thanks for the link

Re: Introduction to the Math of Computer Graphics

#15
post #11
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

Matrices are a way of accumulating a bunch of separate transformations you might want to perform on a point (in the lingo, points are vectors because each coordinate of the point is an element of the vector). Suppose figuring out where a world point (in a game map, for example) should show up on screen (in pixels) looked like a bit like this function call sequence (this is simplified): screenPoint = perspective(move(…

Wonderful explanation, thanks

Re: Introduction to the Math of Computer Graphics

#16

"The Matrix and Quaternions FAQ" is also worth reading: http://www.j3d.org/matrix_faq/matrfaq_latest.html

I've been using quaternions for 15 years now and I still don't have a good mental image of why they work. I've just learned to accept the operations and what they do.

Re: Introduction to the Math of Computer Graphics

#17

"The Matrix and Quaternions FAQ" is also worth reading: http://www.j3d.org/matrix_faq/matrfaq_latest.html

I've been using quaternions for 15 years now and I still don't have a good mental image of why they work. I've just learned to accept the operations and what they do.

Visualising Quaternions is a book which goes into much beautiful depth about what they represent and how they behave, if you fancy digging deeper than the everyday practicality of them.

Re: Introduction to the Math of Computer Graphics

#18
Small thing, but some of the examples have some pretty bad undefined behavior bugs. For instance:

    Matrix& operator*( const double scalar,
                       const Matrix& rhs)
    {
      Matrix result(rhs);
      result *= scalar;
 
      return result;
    }
(Returning a reference to a stack variable is undefined behavior, but realistically you're probably either looking at a hard crash or a really hard to track down bug)

Re: Introduction to the Math of Computer Graphics

#19
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

A 4x4 matrix can represent a position and a rotation, where the 3x3 matrix (called the transform) is the rotation and the 4th row (calls the transpose) is the location in space.

The neat thing is that when you multiply matrices together you update the original matrix. e.g. If you want to rotate something 90degrees to the right, you make a transform matrix with a zero transpose and multiply it with the original matrix. The resulting matrix will be an object in the same place rotated by 90 degrees.

Most modeling applications since about 2000 though use quaternions and a point to represent rotation and location. That's because it uses less memory and is easier/faster to compute.

Re: Introduction to the Math of Computer Graphics

#20
post #4

What I'm failing to understand is how do matrices relate to 3D graphics. What is a matrix representing? I think I get the idea of a vertex, as that can be used to represent a point on a shape, like a 3d model.

Matrices and Linear Transformations by Cullen (Dover Books on Mathematics) will answer all your questions and more. It's written in plain English, doesn't require a mathematical background, and you really only need the first three chapters.
Post reply on HN