• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當(dāng)自強(qiáng)而不息

            D3D編程必備的數(shù)學(xué)知識(shí)(2)

            向量相加

            我們能夠通過分別把兩個(gè)向量的各個(gè)分量相加得到向量之和,注意在相加之前必須保證它們有相同的維數(shù)。

            u + v = (ux+ vx, uy+ vy, uz+ vz)

             

            圖5顯示的是幾何學(xué)上的向量相加。

            兩個(gè)向量相加的代碼,我們使用重載的加法操作符:

            D3DXVECTOR3 u(2.0f, 0.0f, 1.0f);

            D3DXVECTOR3 v(0.0f, -1.0f, 5.0f);

            // (2.0 + 0.0,  0.0 + (-1.0),  1.0 + 5.0)

            D3DXVECTOR3 sum = u + v; // = (2.0f, -1.0f, 6.0f)

             

             

             

            向量相減

            和加法類似,通過分別把兩個(gè)向量的各個(gè)分量相減得到向量之差。再次重聲兩個(gè)向量必須是相同維數(shù)。

            u-v = u + (-v) = (ux - vx, uy - vy, uz - vz)

             

            圖6顯示的是幾何學(xué)上的向量相減。

             

            兩個(gè)向量相減的代碼,我們使用重載的減法操作符:

            D3DXVECTOR3 u(2.0f, 0.0f, 1.0f);

            D3DXVECTOR3 v(0.0f, -1.0f, 5.0f);

            D3DXVECTOR3 difference = u - v; // = (2.0f, 1.0f, -4.0f)

            圖6顯示,向量減法得到一個(gè)從v向量終點(diǎn)到u向量終點(diǎn)的向量。假如我們解釋uv的分量,我們能用向量相減找到從一個(gè)點(diǎn)到另一個(gè)點(diǎn)的向量。這是非常方便的操作,因?yàn)槲覀兂3O胝业綇囊粋€(gè)點(diǎn)到另一個(gè)點(diǎn)的方向向量。

             

             

            標(biāo)量與向量的乘積

            我們能用一個(gè)標(biāo)量與向量相乘,就象名字暗示的一樣,向量按比例變化。這種運(yùn)算不會(huì)改變向量的方向,除非標(biāo)量是負(fù)數(shù),這種情況向量方向相反。

            ku = (kux, kuy, kuz)

            D3DXVECTOR3類提供了向量與標(biāo)量乘法的操作符。

            D3DXVECTOR3 u(1.0f, 1.0f, -1.0f);

            D3DXVECTOR3 scaledVec = u * 10.0f; // = (10.0f, 10.0f, -10.0f)

             

            點(diǎn)積

            數(shù)學(xué)上定義點(diǎn)積是兩個(gè)向量的乘積。按下面等式計(jì)算:

             

            u.v = uxvx + uyvy + uzvz = s

            The above formula does not present an obvious geometric meaning. Using the law of cosines, we can find the relationship u.v = ∥u∥∥v∥ cosθ , which says that the dot product between two vectors is the cosine of the angle between them scaled by the vectors' magnitudes. Thus, if both u and v are unit vectors, then u.v is the cosine of the angle between them.

            Some useful properties of the dot product:

            • If u.v = 0, then uv.

            • If u.v > 0, then the angle θ, between the two vectors is less than 90 degrees.

            • If u.v < 0, then the angle θ, between the two vectors is greater than 90 degrees.

              Note 

            The ⊥ symbol means "orthogonal," which is synonymous with the term "perpendicular."

            We use the following D3DX function to compute the dot product between two vectors:

            FLOAT D3DXVec3Dot(          // Returns the result.
            CONST D3DXVECTOR3* pV1, // Left sided operand.
            CONST D3DXVECTOR3* pV2 // Right sided operand.
            );

            D3DXVECTOR3 u(1.0f, -1.0f, 0.0f);
            D3DXVECTOR3 v(3.0f, 2.0f, 1.0f);

            // 1.0*3.0 + -1.0*2.0 + 0.0*1.0
            // = 3.0 + -2.0
            float dot = D3DXVec3Dot( &u, &v ); // = 1.0

            叉積

            第二種乘法在向量數(shù)學(xué)中叫叉積。不象點(diǎn)積,結(jié)果值是一個(gè)標(biāo)量,叉積的結(jié)果值是另一個(gè)向量。通過把兩個(gè)向量uv相乘得到另一的向量p,向量p垂直于uv。也就是說向量p垂直于u并且垂直于u

            The cross product is computed like so:

            p = u×v = [(uyvz - uzvy), (uzvx - uxvz), (uxvy - uyvx)]

            In component form:

            px = (uyvz - uzvy)

            py = (uzvx - uxvz)

            pz = (uxvy - uyvx)

            Example: Find j = k × i = (0, 0, 1) × (1, 0, 0) and verify that j is orthogonal to both k and i.

            Solution:

            jx =(0(0)-1(0)) = 0

            jy =(1(1)-0(0) = 1

            jz=(0(0)-0(1) = 0

            So, j = (0, 1, 0). Recall from the section titled "Dot Products" that if u.v = 0, then uv Since j.k = 0 and j.i = 0, we know j is orthogonal to both k and i.

            We use the following D3DX function to compute the cross product between two vectors:

            D3DXVECTOR3 *D3DXVec3Cross(
            D3DXVECTOR3* pOut, // Result.
            CONST D3DXVECTOR3* pV1, // Left sided operand.
            CONST D3DXVECTOR3* pV2 // Right sided operand.
            );

            It is obvious from Figure 7 that the vector -p is also mutually orthogonal to both u and v. The order in which we perform the cross product determines whether we get p or -p as a result. In other words, u × v = -(v × u). This shows that the cross product is not commutative. You can determine the vector returned by the cross product by the left hand thumb rule. (We use a left hand rule because we are using a left-handed coordinate system. We would switch to the right hand rule if we were using a right-handed coordinate system.) If you curve the fingers of your left hand in the direction of the first vector toward the second vector, your thumb points in the direction of the returned vector.

             


            posted on 2008-03-12 10:58 lovedday 閱讀(835) 評(píng)論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評(píng)論

            老色鬼久久亚洲AV综合| 欧美亚洲色综久久精品国产| 99久久综合狠狠综合久久| 久久夜色tv网站| 色偷偷91久久综合噜噜噜噜| 伊人久久大香线蕉亚洲| 国产精品久久久久jk制服| 国产激情久久久久影院小草 | 国产午夜精品理论片久久影视 | 久久人妻少妇嫩草AV蜜桃| 7777精品伊人久久久大香线蕉| 伊人久久大香线蕉综合Av| 久久久久国产亚洲AV麻豆| 亚洲AV无码久久寂寞少妇| 国内精品久久久久久久影视麻豆 | 久久99热精品| 久久久久亚洲AV片无码下载蜜桃| 久久亚洲国产欧洲精品一| 亚洲欧洲日产国码无码久久99| 欧美日韩中文字幕久久伊人| 久久久久亚洲精品日久生情| 久久夜色精品国产| 精品一区二区久久| 一本久久a久久精品亚洲| 久久精品无码一区二区三区免费 | 无码精品久久一区二区三区| 国产情侣久久久久aⅴ免费| 欧美黑人激情性久久| 午夜精品久久久久9999高清| 亚洲成色999久久网站| 99精品久久精品| 久久永久免费人妻精品下载| 狠狠色丁香婷婷久久综合| 伊人久久大香线蕉精品不卡| 国产成人精品久久一区二区三区av| 成人妇女免费播放久久久| 欧美精品久久久久久久自慰| 伊人久久大香线蕉亚洲五月天| 成人综合久久精品色婷婷| 亚洲国产小视频精品久久久三级 | 久久亚洲综合色一区二区三区|