日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

球形坐标和Cartesian 坐标的转换 spherical coordinate

發(fā)布時(shí)間:2025/3/15 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 球形坐标和Cartesian 坐标的转换 spherical coordinate 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

??????????? spherical coordinate 和cartesian坐標(biāo)的轉(zhuǎn)換, 個(gè)人認(rèn)為在控制camera的時(shí)候最為有用,比如CS中的操作方式, 鼠標(biāo)負(fù)責(zé)方向的改變,其恰恰就是球形坐標(biāo)的改變。而camera的位置改變就是cartesian的改變,所以這兩者的轉(zhuǎn)換就必不可少了。
??????????? 以下是基本的數(shù)學(xué)公式,非常簡(jiǎn)單。

Thus, we can convert from spherical to Cartesian coordinates by

?

We convert from Cartesian to spherical coordinates by



我的代碼,比較爛不要見笑, 沒什么注釋,比較簡(jiǎn)單大家應(yīng)該可以看懂:

//_horizon, _vertical是球形坐標(biāo)的改變大小

void AO_Camera::moveRatate( float _horizon, float _vertical )

{

float r, s, thi, theta, x, y, z;

x = m_forwardVector.x;

y = m_forwardVector.y;

z = m_forwardVector.z;

r = D3DXVec3Length( &m_forwardVector);

s = D3DXVec3Length( &D3DXVECTOR3( x, 0.0f, z) );

thi = acos( y / r );

//限制theta的改變范圍
if
( x <= 0 )

{

theta = PI - (float)asinf( z / s );

}

else

{

theta = (float)asinf( z / s );

}

?

?


thi = thi + _vertical;

if ( thi <= PRECISION )

{

thi = PRECISION;

}

else if( thi >= PI - PRECISION )

{

thi = PI - PRECISION;

}

theta = theta - _horizon;

m_forwardVector.x = r * sin( thi ) * cos( theta );

m_forwardVector.z = r * sin( thi ) * sin( theta );

m_forwardVector.y = r * cos( thi );

?

m_LookAt = m_EyePos + m_forwardVector;

?

}

作者> chiyuwang

轉(zhuǎn)載于:https://www.cnblogs.com/chiyuwang/archive/2006/09/04/494676.html

總結(jié)

以上是生活随笔為你收集整理的球形坐标和Cartesian 坐标的转换 spherical coordinate的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。