# vectors and vector space. And projection and clip space.

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

## Recommended Posts

Hello, I have a few questions on the topics in the title: 1) Are the vectors we use in 3d graphics the same as the vectors in a vector space? If not, what's the difference? 2) Other then points and vectors being of a completely different nature, are there any other things about vectors that are not usually mentioned? Because I've read quite a few tutorials/books on vectors/matrices and only 2 of them so far have actually made a distinction between vectors and points. So I'm curious if there're any other pointers... 3) If I understand projection correctly. What you have first are the vertices/points in camera space. You then map camera space to projection space by scaling camera space yes? I read something about translation too but I didn't get it. Anyway, are all the points put in the range [-1,1]? Because I've read something about a cuboid frustum coming into play at this stage, but didn't quite get it. If the points are put into [-1,1] range, then how is clipping done? Because as I understand all points *outside* the [-1,1] range are clipped... If the points are not put into the [-1,1] range then what's the deal with this "canonical unit cube frustum" that these books/tutorials keep metioning?

##### Share on other sites
For 3D-graphics, we use "geometrical" or "spatial" vectors, the traditional idea being a magnitude and direction. Similarly to physics, we use the 3D-vectors.

A vector in the mathematical sense need only be an element of a vector space, which is a set satisfying certain axioms. This is a generalization of the "geometrical" vector, with that being a 3D-vector space over the field of real numbers.

A vector space need not be limited to the real numbers, however. Vector spaces can be constructed over any field, including the complex numbers and finite(i.e., boolean) fields. Thus it makes sense to think of binary n-bit numbers as bit-vectors of dimension n over the boolean field.

As for things traditionally not said about vectors, the most common misconception beyond vectors/points is equality with vectors.

Consider a vector written as a linear combination of a basis. And rewrite that as a linear combination of another basis. You might get <2,5> for the first and <3,4> for the second. Are they equal? Yes. They are, but by reflexivity, not symmetry. In fact, they are the exact same vector. You don't just get some kind of "equivilent" vector, it is the exact same vector

In summary, a vector exists independently of the basis from which its coordinates/components are derived. The vector is always the same vector - regardless of basis chosen.

##### Share on other sites
thanks etothex, Im now clear on the first point. As for the second point you're mentioning that "vectors are invarient" thing right?

Anyone with any insight on the 3rd question(s)?

##### Share on other sites
well, this isn't my best area, but here goes...

Basically once you're in camera space, then you apply a "perspective projection" which does the perspective correction and projection in one step.

Consider, the camera as a point object at some (x, y, z). The "frustrum" is a kinda rectangular shaped cone that spreads outfrom the point in the direction the camera is facing. Then, each (3D) point within the frustrum is projected along toward the camera onto the projection plane, where it is indeed in the range -1 to 1, called normalized coordinates. Now it has reached the 2d stage.

From there it's easy to discretize into "image" or "pixel" space, which is the normal 640x480 or 1280x1024 coordinate system the display uses.

##### Share on other sites
Quote:
 Original post by transformation3) If I understand projection correctly. What you have first are the vertices/points in camera space. You then map camera space to projection space by scaling camera space yes? I read something about translation too but I didn't get it. Anyway, are all the points put in the range [-1,1]? Because I've read something about a cuboid frustum coming into play at this stage, but didn't quite get it.If the points are put into [-1,1] range, then how is clipping done? Because as I understand all points *outside* the [-1,1] range are clipped...

Not all the points are put into the [-1, 1] range. Only that points that are originally in your view frustum are mapped into that range. The rest are outside that range and you can clip them. However you want to clip them when they're still homogeneous coordinates, before the perspective divide. You've probably read that part of the perspective projection process is to divide out the W component, like [X/W, Y/W, Z/W, 1]. Before that they're in the form [X, Y, Z, W]. So instead of clipping to the range [-1, 1] after the division, you clip X/Y/Z to the range [-W, W] before the division. That means each point has its own clipping range defined by its W component, but everything works out in the end.

##### Share on other sites
thanks zipster and etothex for your input, I'm still a little confused though. I'll just write doen what I understand so far and the corrections/additions would be appreciated.

1) When in camera space, we're dealing with homogeneous coordinates right.

2) After applying the projection matrix then all the points end up in a "homogeneous" clip space still having 4 coordinates.

3) In homogeneous clip space, the points are clipped against the homogeneous coordinate W. All x, y and z coordinates are clipped to the same w?

4) The projection transform does two things:
--> i) it applies perspective by scaling the points?
--> ii) it projects the points onto the near plane of the frustum? Or does it just map the points into a [-1,1] range? These views will invalidate point number 2 however!

Quote:
 The rest are outside that range and you can clip them. However you want to clip them when they're still homogeneous coordinates, before the perspective divide.

Why?

Quote:

I'll post a link to this topic there... Thanks for the suggestion.

##### Share on other sites
Quote:
 Original post by transformation1) When in camera space, we're dealing with homogeneous coordinates right.

Camera space is what results after you transform the world so that the camera location is at the origin, the Z-axis is the "forward" direction (+Z for DirectX, -Z for OpenGL), the X-axis is the "right" direction, and the Y-axis is the "up" direction, relative to your view. You can think of this as a homogeneous space if you want, but W is always going to be 1 at this point, so you don't have to worry about it.

Quote:
 2) After applying the projection matrix then all the points end up in a "homogeneous" clip space still having 4 coordinates.

After the perspective transformation W doesn't have to be 1 anymore, so now it's important.

Quote:
 3) In homogeneous clip space, the points are clipped against the homogeneous coordinate W. All x, y and z coordinates are clipped to the same w?

Each point has its own W that it's clipped against. So the point [x1,y1,z1,w1] would be clipped against w1, [x2,y2,z2,w2] would be clipped against w2, etc.

Quote:
 4) The projection transform does two things: --> i) it applies perspective by scaling the points? --> ii) it projects the points onto the near plane of the frustum? Or does it just map the points into a [-1,1] range? These views will invalidate point number 2 however!

After you divide out the W so you have (x/w,y/w,z/w,1), it has mapped all the points into the unit cube, with range [-1,1] like you mentioned. However, you now have a parallel space, so the normalized (x,y) values of the points are the same normalized (x,y) values they'd have on screen. Since W is 1 for all the points now, you don't have to worry about homogeneous space anymore.

Quote:
Quote:
 The rest are outside that range and you can clip them. However you want to clip them when they're still homogeneous coordinates, before the perspective divide.

Why?

It's because points behind the camera aren't projected the same as points in front of the camera, after you divide by W. The projected (z/w) value is highly non-linear, as a matter of fact it behaves as the inverse-linear function. The problem with this function is that after the vertical asymptote, the sign of the function completely changes (take a look at its value as it approaches 0 from both sides). In the case of the projection transformation, the camera acts as this asymptote. So a point that's on the near plane will have a (z/w) value of -1. If the point's behind the near plane, but still in front of the camera, the (z/w) value will range from -1 to -inf. But once the point goes behind the camera, the (z/w) value jumps up to +inf, and approaches +1 as it moves farther away from the camera. The problem is that even though the (z/w) is outside the range [-1,+1] (so technically you could perform clipping), it projects to the wrong side of the cube. So if you have a triangle where two points are in front of the camera and one point is behind the camera, the third point will have a (z/w) value that's positive, instead of negative like you'd expect. I hear this would produce invalid texture coordinates. So the clipping is done before the W divide, while all the mappings are still linear. There's some more information here.

##### Share on other sites
Thanks Zipster, that about clears things up for now. I'll be back soo though (probably more "transform" related questions :))

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633420
• Total Posts
3011793
• ### Who's Online (See full list)

There are no registered users currently online

×