zoukankan      html  css  js  c++  java
  • 投影变换 到 uv坐标 xy/w 齐次坐标

    float3 vScreenPos = In.ClipPos.xyz;

    vScreenPos /= In.ClipPos.w;

    vScreenPos.xy += 1.f;

    vScreenPos.xy *= 0.5f;

    vScreenPos.y = 1.f - vScreenPos.y;

    这个是shader里从vertex最后那个pos 里取 uv的算法

    pos是指经过了 world view proj的变换得到的 齐次坐标(x,y,z,w)

    我之前 一直不明白 为什么 要xy/w

    后来 我认为是这样的  齐次坐标系 是为了 将 P‘=M1 *P+M2  (点P P' 变换矩阵M1 M2)

    这种变换 统一到 一个矩阵里表示 就加了一维 使其 把变换统一到 相乘

    进行 world view 变换时 w那里一直是一所以可以把 xyz1->xyz想成空间中的点  做各种变换

      但是 proj之后 w就不是1了   好像 world view 时M2的系数是1 proj时 M2的系数不是1了(这里表述不严谨 大体是这个意思)

       这样 就不能再把 点*Matrix的点当成 空间中对应位置的点 来想象 位置了 这步 就只是个计算 所以最后 要把w除去  以把P‘单独 提出来

    /w只是计算中的一步 没有几何意义

    理解起来 参见 齐次方程 x+y=0              (A)

                   非齐次方程 x + y =b    (B)

    B的解=A的通解+特解

    为什么  x=xh/h  y=yh/h!!

    http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/geometry/homo-coor.html

    因为这里说的这些   符合在这样的 才能使 多项式成为齐次

    再次感慨下 中文搜的东西 基本都雷同 技术资料只能找英文的!!!!!

    One of the many purposes of using homogeneous coordinates is to capture the concept of infinity. In the Euclidean coordinate system, infinity is something that does not exist. Mathematicians have discovered that many geometric concepts and computations can be greatly simplified if the concept of infinity is used. This will become very clear when we move to curves and surfaces design. Without the use of homogeneous coordinates system, it would be difficult to design certain classes of very useful curves and surfaces in computer graphics and computer-aided design.

    Let us consider two real numbers, a and w, and compute the value of a/w. Let us hold the value of a fixed and vary the value of w. As w getting smaller, the value ofa/w is getting larger. If w approaches zero, a/w approaches to infinity! Thus, to capture the concept of infinity, we use two numbers a and w to represent a value v,v=a/w. If w is not zero, the value is exactly a/w. Otherwise, we identify the infinite value with (a,0). Therefore, the concept of infinity can be represented with a number pair like (aw) or as a quotient a/w.

    Let us apply this to the xy-coordinate plane. If we replace x and y with x/w and y/w, a function f(x,y)=0 becomes f(x/w,y/w)=0. If function f(x,y) = 0 is a polynomial, multiplying it with wn will clear all denominators, where n is the degree of the polynomial.

    For example, suppose we have a line Ax + By + C = 0. Replacing x and y with x/w and y/w yields A(x/w) + B(y/w) + C = 0. Multiplying by w changes it to

    Ax + By + Cw = 0.

    Let the given equation be a second degree polynomial Ax2 + 2Bxy + Cy2 + 2Dx + 2Ey + F = 0. After replacing x and y with x/w and y/w and multiplying the result with w2, we have

    Ax2 + 2Bxy + Cy2 + 2Dxw + 2Eyw + Fw2 = 0
    If you look at these two polynomials carefully, you will see that the degrees of all terms are equal. In the case of a line, terms xy and w are of degree one, while in the second degree polynomial, all terms (i.e.x2xyy2xwyw and w2) are of degree two.

    Given a polynomial of degree n, after introducing w, all terms are of degree n. Consequently, these polynomials are called homogeneous polynomials and the coordinates (x,y,w) the homogeneous coordinates.

    Given a degree n polynomial in a homogeneous coordinate system, dividing the polynomial with wn and replacing x/wy/w with x and y, respectively, will convert the polynomial back to a conventional one. For example, if the given degree 3 homogeneous polynomial is the following:

    x3 + 3xy2 - 5y2w + 10w3 = 0
    the result is
    x3 + 3xy2 - 5y2 + 10 = 0

    This works for three-dimension as well. One can replace a point (xyz) with (x/wy/wz/w) and multiply the result by w raised to certain power. The resulting polynomial is a homogeneous one. Converting a degree n homogeneous polynomial in xyz and w back to the conventional form is exactly identical to the two-variable case.

    An Important Notes

    Given a point (x,y,w) in homogeneous coordinates, what is its corresponding point in the xy-plane? From what we discussed for converting a homogeneous polynomial back to its conventional form, you might easily guess that the answer must be (x/w,y/w). This is correct. Thus, a point (3,4,5) in homogeneous coordinates converts to point (3/5,4/5)=(0.6,0.8) in the xy-plane. Similarly, a point (x,y,z,w) in homogeneous coordinates converts to a point (x/w,y/w,z/w) in space.

    Conversely, what is the homogeneous coordinates of a point (x,y) in the xy-plane? It is simply (x,y,1)! That is, let the w component be 1. In fact, this is only part of the story, because the answer is not unique. The homogeneous coordinates of a point (x,y) in the xy-plane is (xwyww) for any non-zero w. Why is this true? Because (xwyww) is converted back to (x,y). As a result, the following is important for you to memorize:

    Converting from a homogeneous coordinates to a conventional one is unique; but, converting a conventional coordinates to a homogeneous one is not.
    For example, a point (4,2,3) in space is convert to (4w, 2w, 3ww) for any non-zero w.

    The Dimensionality of Homogeneous Coordinates

    You perhaps have discovered that homogeneous coordinates need 3 and 4 components to represent a point in the xy-plane and a point in space, respectively. Therefore, a point in space (resp., the xy-plane) in homogeneous coordinates actually has four (resp.third) components. Adding a fourth (resp., third) component whose value is 1 to the coordinates of a point in space (resp., the xy-plane) converts it to its corresponding homogeneous coordinates.

    Ideal Points or Points at Infinity

    As mentioned at the very beginning of this page, homogeneous coordinates can easily capture the concept of infinity. Let a point (x,y) be fixed and converted to a homogeneous coordinate by multiplying with 1/w, (x/w,y/w,1/w). Let the value of w approach to zero, then (x/w,y/w) moves farther and farther away in the direction of (x,y). When w becomes zero, (x/w,y/w) moves to infinity. Therefore, we would say, the homogeneous coordinate (x,y,0) is the ideal point or point at infinity in the direction of (x,y).

    Let us take a look at an example. Let (3,5) be a point in the xy-plane. Consider (3/w,5/w). If w is not zero, this point lies on the line y = (5/3) x. Or, if you like the vector form, (3/w,5/w) is a point on the line O + (1/w)d, where the base point O is the coordinate origin and d is the direction vector <3,5>. Therefore, as wapproaches zero, the point moves to infinity on the line. This is why we say (x,y,0) is the ideal point or the point at infinity in the direction of (x,y).

    The story is the same for points in space, where (x,y,z,0) is the ideal point or point at infinity in the direction of (x,y,z).

    The concept of homogeneous coordinates and points at infinity in certain direction will become very important when we discuss representations of curves and surface.

    A Simple Geometric Interpretation

    Given a homogeneous coordinate (x,y,w) of a point in the xy-plane, let us consider (x,y,w) to be a point in space whose coordinate values are xy and w for the x-,y- and w- axes, respectively. The line joining this point and the coordinate origin intersects the plane w = 1 at a point (x/wy/w, 1). Please verify this fact yourself. The following figure illustrates this concept.

    This transformation treats a two-dimensional homogeneous point as a point in three-dimensional space and projects (from the coordinate origin) this three-dimensional point to the plane w=1. Therefore, as a homogeneous point moves on a curve defined by homogeneous polynomial f(x,y,w)=0, its corresponding point moves in three-dimensional space, which, in turn, is projected to the plane w=1. Of course, (x/w,y/w) moves on a curve in plane w=1.

    The above figure also shows clearly that while the conversion from the conventional Euclidean coordinates to homogeneous coordinates is unique, the opposite direction 

  • 相关阅读:
    【转】 hive简介,安装 配置常见问题和例子
    MapReduce 开发环境搭建(EclipseMyEclipse + Maven)
    Hadoop项目开发环境搭建(EclipseMyEclipse + Maven)
    Eolinker——前置用例的使用
    github------删除Repository
    Git----创建远程分支,并将文件上传到创建的远程分支上
    Git-------常用操作记录
    gitlab和github的区别
    APP线上问题收集信息整理
    缺陷管理协作流程与注意点
  • 原文地址:https://www.cnblogs.com/minggoddess/p/2013842.html
Copyright © 2011-2022 走看看