Linear Transform From 3D Space To 2D Space
Author: Kagula
Date: 2010-03-23
简介:
本文是文章后半部分所列教材的学习笔记。
Introduction
How a point from the 3d cartesian space project to window space. I explanation it used Matlab language symantics.I assume the reader be familiar with matlab and linear algebra.
World Space To Camera Space
Here I suppose a point is in the 3d cartesian space,other words is in the world space. It’s already undergo the linear transform of some rotation , translation , uniform scales and the shear.
Now I stand in the original point and want view the star in the sky, how can I see it.
Assume the star is a point in the world space I call it Xworld. The same point I see with my eye is in my view space(also name it camera space).How to transform the point from world space to camera space.
First I assume the point in the 4d tuple.The coordinate I defined here is, A Axis Left to right is positive direction I call it x axis. Down to up and perpendicular to x axis is y axis. Another axis perpendicular with x and y axis is z axis,From your eye to the monitor is positive direction. Where they cross is original point,I assigned it to(0,0,0). The fourth component of the point I defined 1,why be 1 I discuss later.
Xworld=[x1,y1,z1,1]’
Xview =[x2,y2,z2,1]’
Mview=[a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34]
So the identity should be like this
Xview=Mview*Xworld. (1-1)
Mview is a function how to evaluate it.
You can imagine you stand in the world center of 2d cartesian but how about if you stand left offset 1 unit distance from the original of the x axis. Yes the object like move to right a one unit distance. So x component of the Xview should plus one unit.
I define E is where you stand, So the equality should be like it
Xview = Xworld – E (1-2)
Now I think the matrix Mview=[eye(3) -eye(3)*E;0 1],which from the reference [2].Substituting the symbol with you particular value,you will find it equal to (1-2)
Below snippet is the example,where Ex、Ey、Ez is component of the E
-[1 0 0;0 1 0;0 0 1]*[Ex Ey Ez]’=-[Ex Ey Ez]’
[eye(3) –[Ex Ey Ez]’;0 0 0 1]=[ 1 0 0 –Ex; 0 1 0 –Ey;0 0 1 –Ez;0 0 0 1]=Mview (1-3)
Also show (1-1) with substituting Mview with (1-3) equal to (1-2) left the fourth component of the Xview is 1.
Camera Space To Clip Space(Perspective Projection)
Before dive the paragraph you should know what is the view frustum and what is the orthographic projection,about it reference [2] Page94 Figure 4.19,Page 89.
Step1: Projection
Assume a point P in the view frustum, P project to the point q in the view plane(near plane),we can get the below equation
qx/px = qz/pz => qx = qz*(px/pz) (2-1) then we get the matrix below
Mproj=[ 1 0 0 0;0 1 0 0;0 0 1 0;0 0 1/qz 0] (2-2) OpenGL
Mproj’=[1 0 0 0; 0 1 0 0;0 0 1 1/qz;0 0 0 0] (2-3) DirectX
Step2: To normalized device coordinate
I express it in terms of the six-tuple(l,r,b,t,n,f),denoting the left,right,bottom,top,near and far.l is you can see the most left edge,r is you can see the most right edge,the other is so on.
Before projection,[input-1]we determined the depth we see is near plane from the far plane. [input-2] fovy ,Field of view in the y direction, in radians. [input-3]As pect ratio, The ratio defined as view space width divided by height.
Then we evaluated [Output](l,r,b,t,n,f)
Reference《D3DXMatrixPerspectiveFovLH Function》http://msdn.microsoft.com/en-us/library/bb205350(VS.85).aspx
Because
X_output = 2/(l-r)(n*x_input) (2-4)
Y_output = 2/(b-t)(n*y_input) (2-5)
Z_output = ( n/(f-n) )*(z_input-n) (2-6)
So the matrix is which D3DXMatrixPerspectiveFovLH is.Detail see R1P55Equation(2.68)
The R1P55Equation(2.67) have some complicate,You should be familiar with “Lines Project to Lines”
Below matlab code will show the relationship about the concept
%begin
S=0:1/100:1;
W0 = 0.1;w1=1; %w0 is Near,w1 is Far
S2=(W1.*s)./(w0+(w1-w0).*s) %R1P37Equation(2.44)
Plot(s,s2,’-r’,s,s,’-b’);
Xlabel(‘s’),ylabel(‘s2’);
Axis(‘square’)
grid
%end
Now the objects is in the unit cube,left to right is 1 to -1,top from bottum is 1 to -1,near to far is 0 to 1(DirectX) or -1 to 1(OpenGL)
After perspective divide (Reference 2-1 )the point in 3d space can project to 2d space(also can be windows coordinate)
I have not considered the view frustum screw,because I can not understand it now, whatever in directX9 is no concern.
Reference
[1]《3D Game Engine Design-Apractical Approach to Real-Time Computer Graphics》(Second Edition) David H. Eberly 2007
[2]《Real-Time Rendering》(Third Edition) Tomas Akenine-Moller ,Eric Haines,Naty Hoffman 2008
[3]《Linear Algebra:An Interactive Approach》Jain,S.K. , Gunawardena,A.D. 2003
[4]《DirectX Documentation for C++》(Microsoft DirectX SDK (November 2008))45ret
分享到:
相关推荐
When.Life.Is.Linear.From.Computer.Graphics.to.Bracketology
Linear Canonical Transform.docx
TensorFlow for Deep Learning From Linear Regression to Reinforcement Learning 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Linear Space Alignment Algorithm
Gilbert Strang's textbooks have changed the entire approach to learning linear algebra -- away from abstract vector spaces to specific examples of the four fundamental subspaces: the column space and ...
Introduction to Linear Optimization, 1997. by Bertsimas and Tsitsiklis
Gilbert Strang's textbooks have changed the entire approach to learning linear algebra -- away from abstract vector spaces to specific examples of the four fundamental subspaces: the column space and ...
Linear Algebra: Foundations to Frontiers (LAFF) is an experiment in a number of different dimensions. • It is a resource that integrates a text, a large number of videos (more than 270 by last count)...
Linear Algebra and Learning from data by Gilbert Strange pdf
运筹学中最经典的线性优化讲解教材,英文完整版(目前市面上大多是1-5章,本版本为完整版,但对印刷质量要求较高的朋友们慎下),希望能对研究线性优化的朋友们提供帮助!与君共勉~~
Gilbert Strang编写的Introduction to Linear Algebra第五版习题解答 清晰
Gilbert Strang的书改变了学习线性代数的整个方法,本书为其书的第三版
线性优化讲义 introduction to linear optimization ,
Introduction to Linear Algebra 4th Edition Solutions to Exercises 《线性代数导论》第四版 课后习题讲解
介绍线性回归、逻辑回归等,并结合实际案例介绍这些回归方法
Introduction to Linear Algebra第五版英文原版。希望查看英文原版的,请下载
线性代数的许多应用都需要时间来发展。...中文翻译Introduction to Linear Algebra, 5th Edition 9.3节 单位根与傅里叶矩阵 二次方程有两个根(或者一个重根)。n 次方程具有 n 个根(算上重复次数)。这是代数基本定
我们目前正处于一场数据革命之中。在科学、健康甚至日常生活中产生的海量和不断增长的数据集将影响社会的许多领域。许多这样的数据集不仅大,而且是高维的,每个数据点可能包含数百万甚至数十亿个数字。...
Introduction to Linear Algebra, Fifth Edition, Gilbert Strang, 习题答案
Stanford18.06课程教材: introduction to linear algebra